JUnit: (possibly indirectly) contains itself as a

2019-02-27 01:00发布

I want to add a subtest, FailingIO, to FailingTest while inheriting the parent's useful methods

@RunWith(Suite.class)
@Suite.SuiteClasses({FailingTest.FailingIO.class})
class FailingTest {

  @Test
  test1() {}


  static class FailingIO extends FailingTest {

I am getting JUnit: (possibly indirectly) contains itself as a SuiteClass because the annotations are also inherited, I guess. Is there a way to inherit only the methods and leave the annotations to the parent?

I see in Eclipse that Suite.SuiteClasses has the @Inherited but JUnit API has not such attribute. What is going on? What is the JUnit versioning policy regarding the option?

update I see that it is possible to construct a test suite dynamically, e.g. here, here and here. But when do I exploit that for extending FailingTest with FailingIO? Where do I define this code and who will consume the produced subsuite?

update I have checked the HierarchicalContextRunner. It does not contain itself but sadly executes the parent-inherited tests.

0条回答
登录 后发表回答