maven-surefire-plugin包含单一测试不起作用

mbskvtky  于 12个月前  发布在  Maven
关注(0)|答案(3)|浏览(143)

要从Maven pom.xml执行单个Test,我们可以从maven surefire插件执行它。
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <includes>
                    <include>App.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

字符串
但是,它不工作,因为现在.有些东西是失踪申报?我记得,前几个月一旦我执行它,它的工作.
控制台:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< mavenSampleProject01:mavenSampleProjects >--------------
[INFO] Building mavenSampleProjects 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenSampleProjects ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Desktop-pc\eclipse-workspace\mavenSampleProjects\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mavenSampleProjects ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mavenSampleProjects ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Desktop-pc\eclipse-workspace\mavenSampleProjects\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mavenSampleProjects ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ mavenSampleProjects ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.371 s
[INFO] Finished at: 2018-10-02T11:58:27+05:30
[INFO] ------------------------------------------------------------------------

1cklez4t

1cklez4t1#

您需要提供完整的限定类名才能通过surefire plugin. https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html包含它
或者,您可以使用正则表达式,如“**/* App.java”

mec1mxoz

mec1mxoz2#

添加以下插件到您的POM文件。

<plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>

字符串

6rqinv9w

6rqinv9w3#

我发现,Maven test只能从src/test/java包中运行

不考虑从src/main/java运行

如果需要考虑src/main/java,我们必须添加<testSourceDirectory>元素

<build>
    <testSourceDirectory>src/main/java</testSourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <includes>
                    <include>**/app.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

字符串

相关问题