Is there a JUnit TestRunner for running groups of tests?

前端 未结 9 764
既然无缘
既然无缘 2021-02-05 13:42

I am currently using JUnit 4 and have a need to divide my tests into groups that can be run selectively in any combination. I know TestNG has a feature to annotate tests to assi

9条回答
  •  执念已碎
    2021-02-05 14:16

    Check out Spring's SpringJUnit4ClassRunner. I've used it to optionally run tests based on a System property, using the IfProfileValue annotation.

    This:

    @IfProfileValue(name="test-groups", values={"unit-tests", "integration-tests"})
      public void testWhichRunsForUnitOrIntegrationTestGroups() {
          // ...
     }
    

    Will run if the System property 'test-groups' is set to either 'unit-tests' or 'integration-tests'.

    Update: JUnitExt has @Category and @Prerequisite annotations and looks like it should do what you need. However, I've never used it myself, so I can't vouch for it.

提交回复
热议问题