Any annotation to mark a class as a testclass?

我们两清 提交于 2019-12-08 05:20:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!