Hi Basher,

Bashar Abdul Jawad wrote on Wednesday, January 24, 2007 12:19 AM:

> 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:

[snip]

The current release of the surefire plugin does not support TestSuites 
(unfortunately). It simply collects all TestCases and looks for methods that 
match the standard testXXX pattern.

> 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);
> 
> }

Concidence: Your method name matches now the pattern and the surefire plugin 
will run this "test".

> 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).

Well, as explained, for surefire this *is* indeed a single test. Since all 
errors are handled inside the TestSetup.run() and only collected in the 
TestResult, from surefire's point of view anything is fine.

> 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?

Currently not. I don't know if the current SNAPSHOT of the plugin already has 
any kind of support. You may check JIRA for open issues or resolved/closed ones 
since the last release.

- Jörg

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to