英文:
Skip a specific test class during maven verify phase
问题
我有几个用@RunWith
和@ContextConfiguration
注释的测试类。
我在我的Maven SpringBoot项目中使用以下依赖项:
<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
但是测试仍然被执行而没有被忽略,在verify
阶段。
我该如何跳过它?
谢谢
编辑:
我更喜欢不使用@Ignore
,因为我需要在某个时候手动运行那个特定的测试。
我所需要的只是在运行所有其他测试时排除它。
英文:
I have several test classes annotated with @RunWith
and @ContextConfiguration
.
I use the following dependencies in my maven SpringBoot project:
<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>
and when I run mvn clean verify
it executes all my test classes.
Now I have a specific test class that I want to ignore during the verify
phase.
I tried to annotate it with @ConditionalOnProperty
, so at the end the class is as following:
@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 {
so I have added a property inside my application-test.properties
file:
test.api.real.run=false
but the test is still executed and not ignored, during the verify
phase.
How can I skip it?
Thanks
edit:
I prefer not to use @Ignore
because I need at some point to run that specific test manually.
What I just need is to exclude that one when all the other tests are running.
答案1
得分: 1
你可以在你的测试类上使用注解@ignore
,如果你使用的是 Junit 4,否则你可以使用以下命令:
mvn -Dtest=\!YourTest* install
但我认为,由于你使用的是 Spring Boot 而不是 Spring,更好的答案应该是:https://stackoverflow.com/questions/39048171/how-to-run-turn-off-selective-tests-based-on-profiles-in-spring-boot
英文:
You can use the annotation @ignore
on your test class if you are using Junit 4 or else you could use the command as follows :
mvn -Dtest=\!YourTest* install
but I think since you are using springboot and not spring the better answer would be : https://stackoverflow.com/questions/39048171/how-to-run-turn-off-selective-tests-based-on-profiles-in-spring-boot
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论