Use Categories feature in JUnit4.
Example: if some methods scattered both in ATest
and BTest
are expected to executed :
//Define Categories
@RunWith(Categories.class)
@IncludeCategory(NeedTest.class)
@SuiteClasses({ ATest.class, BTest.class })
class MySuite{
...
}
Then in ATest
and BTest
, annotate your expect methods as:
@Test
@Category(NeedTest.class)
public void test()
When you run MySuite
, only the methods annotated with @Category(NeedTest.class)
will be executed. Of course, you could create multiple test categories,
ps: NeedTest.class is just a marker class, it can be any class.