简体   繁体   English

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

[英]maven-surefire-plugin inclusion of Single test is not working

To execute single Test from Maven pom.xml, we can executed it from maven surefire plugin. 要从Maven pom.xml执行单个测试,我们可以从maven surefire插件执行它。

http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html 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>

But, Its not working as of now. 但是,它到目前为止无法正常工作。 Something is missing to declare ? 有什么东西需要宣布吗? I remember, before few months once I have execute it and it worked. 我记得,几个月前我执行了它,并且它起作用了。

Console : 安慰 :

[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] ------------------------------------------------------------------------

You need to provide full qualified class name to include it by surefire plugin. 您需要提供完全合格的类名,以确保将其包含在surefire插件中。 https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

Alternatively you can use regex like "**/*App.java" 另外,您可以使用正则表达式,例如“ ** / * App.java”

Add below plugins to your POM file. 将以下插件添加到您的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>

I have found that, Maven test only runs it from src/test/java package 我发现, Maven测试仅从src / test / java包运行

It does not consider to run it from src/main/java 它不考虑从src / main / java运行它

If it need to consider src/main/java, We have to add <testSourceDirectory> element 如果需要考虑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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM