是否有任何注释将一个类标记为testclass? [英] Any annotation to mark a class as a testclass?
本文介绍了是否有任何注释将一个类标记为testclass?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Junit4的新手,我想知道是否有一些注释将类标记为测试类,就像使用
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,将方法标记为测试方法.
@Test to mark a method as a test method.
推荐答案
您可以在类级别使用@Category
批注,例如:
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));
}
}
我引用了> https://www.mkyong.com/unittest /junit-categories-test/
另外,如果您运行Spring测试,使用JUnit进行Mockito测试,则必须在类级别使用@RunWith
批注.
Also if you run Spring tests, Mockito test with JUnit, then you have to use @RunWith
annotation at class level.
例如,在Spring Boot测试中,我使用以下代码:
For example in Spring boot test I use this:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
public class ControllerTest {
在Mockito(没有弹簧测试)测试中,我使用了:
In Mockito (without spring test) test I used:
@RunWith(MockitoJUnitRunner.class)
public class ServiceTest {
这篇关于是否有任何注释将一个类标记为testclass?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文