编写 junit 时如何为 Mockito 创建测试套件
How to create test suite for Mockito when we are writing junit
如何为 Mockito 创建测试套件,当我们有多个 class 有 mockito 测试用例时
我尝试将@RunWith(MockitoJUnitRunner.class) 与@SuiteClasses({SampleTest.class,DummyTest.class}) 一起使用,但抛出错误。当我 运行 单独 运行 没问题。
@RunWith(MockitoJUnitRunner.class)
@SuiteClasses({SampleTest.class,DummyTest.class})
public class TestSuiteExample
{
}
org.mockito.exceptions.base.MockitoException:
No tests found in LoginHistoryBLTestSuite
Is the method annotated with @Test?
Is the method public?
at org.mockito.internal.runners.RunnerFactory.create(RunnerFactory.java:75)
at org.mockito.internal.runners.RunnerFactory.createStrict(RunnerFactory.java:40)
at org.mockito.junit.MockitoJUnitRunner.<init>(MockitoJUnitRunner.java:154)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
要创建指定 类 的测试套件,您可以使用:
@RunWith(JUnitPlatform.class)
@SelectClasses( { ServiceTest.class, ControllerTest.class } )
public class Suite {
}
或指定包:
@RunWith(JUnitPlatform.class)
@SelectPackages( { "com.service","com.controller" } )
public class Suite {
}
实际上,当您使用 MockitoRunner 时,您不能 运行 测试用例套件。相反,他们会单独 运行。
如何为 Mockito 创建测试套件,当我们有多个 class 有 mockito 测试用例时
我尝试将@RunWith(MockitoJUnitRunner.class) 与@SuiteClasses({SampleTest.class,DummyTest.class}) 一起使用,但抛出错误。当我 运行 单独 运行 没问题。
@RunWith(MockitoJUnitRunner.class)
@SuiteClasses({SampleTest.class,DummyTest.class})
public class TestSuiteExample
{
}
org.mockito.exceptions.base.MockitoException:
No tests found in LoginHistoryBLTestSuite
Is the method annotated with @Test?
Is the method public?
at org.mockito.internal.runners.RunnerFactory.create(RunnerFactory.java:75)
at org.mockito.internal.runners.RunnerFactory.createStrict(RunnerFactory.java:40)
at org.mockito.junit.MockitoJUnitRunner.<init>(MockitoJUnitRunner.java:154)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
要创建指定 类 的测试套件,您可以使用:
@RunWith(JUnitPlatform.class)
@SelectClasses( { ServiceTest.class, ControllerTest.class } )
public class Suite {
}
或指定包:
@RunWith(JUnitPlatform.class)
@SelectPackages( { "com.service","com.controller" } )
public class Suite {
}
实际上,当您使用 MockitoRunner 时,您不能 运行 测试用例套件。相反,他们会单独 运行。