英文:
how to avoid runing testcases without using skipTests in maven while using the mvn clean install
问题
我已经编写了测试用例,但在运行mvn clean install时激活了这些测试用例,虽然测试用例也在运行,但在运行mvn clean install时,我的情况不需要运行测试用例,只有在使用特定配置文件时才激活这些测试用例。
英文:
I have written the test cases but it is activating when I am running the mvn clean install test cases also running but my case no need to run the test cases while running the mvn clean install when I am using the particular profile then only activate the test cases.
答案1
得分: 1
您可以在您的pom.xml中配置Surefire插件,根据测试名称来包含/排除测试,并为您想要在这些测试上运行的配置使用不同的配置。类似于:
<profiles>
<profile>
<id>without-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<excludes>
<exclude>**/someTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>without-other-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<excludes>
<exclude>**/otherTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
在此链接中了解更多信息。
英文:
You can configure surefire plugin in your pom.xml to include/exclude tests based on their names, and use different configuration for the profiles you want to run these tests on.
Something like:
<profiles>
<profile>
<id>without-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<excludes>
<exclude>**/someTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>without-other-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<excludes>
<exclude>**/otherTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
See more about it here
答案2
得分: 0
将你不想运行的测试用例命名时,使用后缀来对它们进行分组...
例如,有时我们使用 ...FunctionalTest
来标记功能测试。这些测试用例在运行单元测试时可以被分组、包含或排除在外,作为标准构建的一部分。
更多信息请参阅此帖子:https://stackoverflow.com/questions/25273160/how-to-permanently-exclude-one-test-class-in-a-maven-build
英文:
Name the tests you dont want to run with a suffix that enables you to group them ...
e.g. sometimes we use ...FunctionalTest
to label functional tests. These tests can then be grouped/included/excluded when running unit tests, as a part of the standard build.
See this post for more info https://stackoverflow.com/questions/25273160/how-to-permanently-exclude-one-test-class-in-a-maven-build
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论