如何解决在Maven验证阶段跳过特定的测试类
我有几个用backend-server
和Service
注释的测试类。
我在Maven SpringBoot项目中使用以下依赖项:
@RunWith
当我运行@ContextConfiguration
时,它将执行我所有的测试类。
现在,我有一个特定的测试类,我想在<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
阶段忽略。
我尝试用mvn clean verify
对其进行注释,所以最终该类如下:
verify
所以我在@ConditionalOnProperty
文件中添加了一个属性:
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = { RestTemplate.class,AvailabilityService.class,VerifyService.class,ConfirmService.class })
@ComponentScan(basePackages = "it.alpitour")
@TestPropertySource("classpath:application-test.properties")
@ConditionalOnProperty("test.api.real.run")
public class ToIgnoreTest {
但是在application-test.properties
阶段,测试仍然执行并且未被忽略。
我如何跳过它?
谢谢
修改:
我不希望使用test.api.real.run=false
,因为我有时需要手动运行该特定测试。
我只需要在所有其他测试都在运行时就排除那个。
解决方法
如果您使用的是Junit 4,则可以在测试类上使用注释@ignore
,否则,可以使用以下命令:
mvn -Dtest=\!YourTest* install
但是我认为,由于您使用的是springboot而不是spring,所以更好的答案是:how to run/turn off selective tests based on profiles in spring boot
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。