Question

Test suites in Junit4 run nicely, but there's a snag here:

@RunWith(Suite.class)
@Suite.SuiteClasses({ A.class, B.class, ...})

If somebody develops a unit test and forgets to include it in Suite.SuiteClasses, that's obviously a problem.

(that's not a burning problem since Ant will catch that later but still)

So I wondered: if you have say "test" folder in Eclipse project and there are some packages with classes in it - is there a way to include them all automatically in junit4 test suite somehow?

(yes you can right-click "test" folder and do Run as Junit but that sometimes fails individual tests for some reason while they individually pass so I do not have much trust in this solution, plus test suites are nice toys to play with ;-)).

Was it helpful?

Solution

I suggest ClasspathSuite

import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith;
@RunWith(ClasspathSuite.class)
public class MySuite {}

OTHER TIPS

Not an answer but more then comment:

[...] Run as Junit but that sometimes fails individual tests for some reason while they individually pass [...]

The reason is that some tests don't clean up correctly. This should always put you on alert. Try to identify a pair of tests that can't be executed in one "run" and have a close look at the first test. From my own experience: fix those issues as soon as possible (aka: NOW!), otherwise you may run in very deep problems later (typically: complaints from QA guys, like "the tests fail on my environment")

i don't agree with Andreas_D. it's not because tests don't clean after themselves. good unit tests don't have to clean after themselves. it's because your some of your tests depends on result of another. you need better tests and/or fixtures

however i agree with part 'fix them now!'. you have a serious problem when results of your tests are not reproducible

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top