问题
I am new to Junit4, I am wondering if there is some annotations to mark a class as a test class just like using
@Test to mark a method as a test method.
回答1:
You can use @Category
annotation at class level, like:
@Category({PerformanceTests.class, RegressionTests.class})
public class ClassB {
@Test
public void test_b_1() {
assertThat(1 == 1, is(true));
}
}
I quoted this example from https://www.mkyong.com/unittest/junit-categories-test/
Also if you run Spring tests, Mockito test with JUnit, then you have to use @RunWith
annotation at class level.
For example in Spring boot test I use this:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
public class ControllerTest {
In Mockito (without spring test) test I used:
@RunWith(MockitoJUnitRunner.class)
public class ServiceTest {
来源:https://stackoverflow.com/questions/45241313/any-annotation-to-mark-a-class-as-a-testclass