Hello,
I am using junit TestSetup to set up a common selenium connection among my
different tests. The TestSetup runs a global setup and Teardown once before
any of the tests are run. I wrapped a TestSuite in a subclass of TestSetup
and it works perfectly fine when the TestSuite is run from eclipse:
The code for my TestSuite:
public class AllTestsOneTimeSetup {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(SomeTest.class);
TestSetup wrapper = new TestSetup(suite) {
protected void setUp() {
oneTimeSetUp();
}
protected void tearDown() {
oneTimeTearDown();
}
};
return wrapper;
}
}
Now to make this suite runs in Maven 2 I had to add the following method to
the TestSuite:
public void testSuite(){
TestSetup test = (TestSetup) AllTestsOneTimeSetup.suite();
TestResult result = new TestResult();
test.run(result);
}
Now something weird happens. The global setup an tear down run fine and
Maven 2 runs all the tests in the suite fine but It always reports that it
is running 1 test (the testSuite test) and that it was successful (as the
testSuite itself doesn't fail, the included tests do).
One way around this is to do the following:
if (!result.wasSuccessful()){
String message = "";
for (Enumeration e = result.failures(); e.hasMoreElements() ;){
message += e.nextElement() + "\n";
}
for (Enumeration e = result.errors(); e.hasMoreElements() ;){
message += e.nextElement() + "\n";
}
Assert.fail(message);
result.endTest(test);
}
My question is, does anyone have a cleaner solution to this?
Thanks,
Bashar