如何在使用mvn clean install时避免运行测试用例,而不使用skipTests?

huangapple go评论68阅读模式
英文:

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:

&lt;profiles&gt;
	&lt;profile&gt;
		&lt;id&gt;without-tests&lt;/id&gt;
		&lt;build&gt;
			&lt;plugins&gt;
				&lt;plugin&gt;
					&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
					&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
					&lt;version&gt;3.0.0-M5&lt;/version&gt;
					&lt;configuration&gt;
						&lt;excludes&gt;
							&lt;exclude&gt;**/someTests.java&lt;/exclude&gt;
						&lt;/excludes&gt;
					&lt;/configuration&gt;
				&lt;/plugin&gt;
			&lt;/plugins&gt;
		&lt;/build&gt;
	&lt;/profile&gt;
	&lt;profile&gt;
		&lt;id&gt;without-other-tests&lt;/id&gt;
		&lt;build&gt;
			&lt;plugins&gt;
				&lt;plugin&gt;
					&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
					&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
					&lt;version&gt;3.0.0-M5&lt;/version&gt;
					&lt;configuration&gt;
						&lt;excludes&gt;
							&lt;exclude&gt;**/otherTests.java&lt;/exclude&gt;
						&lt;/excludes&gt;
					&lt;/configuration&gt;
				&lt;/plugin&gt;
			&lt;/plugins&gt;
		&lt;/build&gt;
	&lt;/profile&gt;
&lt;/profiles&gt;

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

huangapple
  • 本文由 发表于 2020年10月5日 15:59:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/64204591.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定