springboot 单体测试得时候,因为springboot封装了junit框架,所以无需再手动添加。只需要在pom.xml中添加依赖就可以使用junit进行测试
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
我在测试的时候想要多个测试套件(public 类)一起运行,这样子就不用手动地每个套件运行一遍。我们只需在一个Runner类中添加注解@RunWith(Suite.class) @Suite.SuiteClasses({xxxrTest.class,xxxTest.class})
,这样在运行的时候就会全部测试套件一起运行。
**需要注意的是:@RunWith()
参数需要使用Suite.class
,而不能用SpringRunner.class
。加入其他类一起运行用的是@Suite.SuiteClasses()
,而不是@SuiteClasses
。
这是我在测试的时候碰到很头疼的问题,经过几天查找终于发现了问题。