詹金斯不执行Junit测试类(Maven项目) [英] Jenkins not executing Junit Test class (Maven Project)

查看:85
本文介绍了詹金斯不执行Junit测试类(Maven项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins的新手,所以我有一个Java Web项目(Maven)和一个单元测试文件.测试文件结构:src/test/java/PreProcessorTest.java

New to Jenkins, So I have a java web project (maven) and a Unit test file for it. Test File Structure : src/test/java/PreProcessorTest.java

该测试已在intellij中成功执行.但是Jenkins并未考虑该测试文件,并说构建成功.

The test is successfully executed in intellij. But Jenkins is not considering this test file and saying build as successful.

它显示没有要运行的测试"

It Shows " There are no tests to run"

Jenkins控制台日志

Jenkins Console Log

Commit message: "Update pom.xml"
Parsing POMs
Established TCP socket on 33330
maven35-agent.jar already up to date
maven35-interceptor.jar already up to date
maven3-interceptor-commons.jar already up to date
[DEVACDMY-29158] $ java -cp /home/jenkins/jenkins/maven35-agent.jar:/home/jenkins/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5/boot/plexus-classworlds-2.5.2.jar:/home/jenkins/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5/conf/logging jenkins.maven3.agent.Maven35Main /home/jenkins/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.5 /home/jenkins/jenkins/remoting.jar /home/jenkins/jenkins/maven35-interceptor.jar /home/jenkins/jenkins/maven3-interceptor-commons.jar 33330
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f /home/jenkins/jenkins/workspace/DEVACDMY-29158/pom.xml install
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for groupId:npl:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.mockito:mockito-all:jar -> duplicate declaration of version 2.0.2-beta @ line 85, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] ----------------------------< groupId:npl >-----------------------------
[INFO] Building npl 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ npl ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/jenkins/jenkins/workspace/DEVACDMY-29158/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ npl ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ npl ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/jenkins/jenkins/workspace/DEVACDMY-29158/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ npl ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to /home/jenkins/jenkins/workspace/DEVACDMY-29158/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.8.1:test (default-test) @ npl ---
[INFO] Surefire report directory: /home/jenkins/jenkins/workspace/DEVACDMY-29158/target/surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[JENKINS] Recording test results
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ npl ---
[INFO] Building jar: /home/jenkins/jenkins/workspace/DEVACDMY-29158/target/npl-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ npl ---
[INFO] Installing /home/jenkins/jenkins/workspace/DEVACDMY-29158/target/npl-1.0-SNAPSHOT.jar to /home/jenkins/.m2/repository/groupId/npl/1.0-SNAPSHOT/npl-1.0-SNAPSHOT.jar
[INFO] Installing /home/jenkins/jenkins/workspace/DEVACDMY-29158/pom.xml to /home/jenkins/.m2/repository/groupId/npl/1.0-SNAPSHOT/npl-1.0-SNAPSHOT.pom
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.300 s
[INFO] Finished at: 2020-03-19T04:06:01-05:00
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /home/jenkins/jenkins/workspace/DEVACDMY-29158/pom.xml to groupId/npl/1.0-SNAPSHOT/npl-1.0-SNAPSHOT.pom
[JENKINS] Archiving /home/jenkins/jenkins/workspace/DEVACDMY-29158/target/npl-1.0-SNAPSHOT.jar to groupId/npl/1.0-SNAPSHOT/npl-1.0-SNAPSHOT.jar
channel stopped
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: SUCCESS

pom.xml

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
       <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
           <junit.jupiter.version>5.6.0</junit.jupiter.version>
           <maven.compiler.release>11</maven.compiler.release>
                 <project.build.testSourceDirectory>src/test/java</project.build.testSourceDirectory>
    </properties>
             <build>
             <plugins>
             <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.8.1</version>
    </plugin>
             </plugins>
             </build>

        <groupId>groupId</groupId>
        <artifactId>npl</artifactId>
        <version>1.0-SNAPSHOT</version>
        <dependencies>
            <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-servlet-api -->
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-servlet-api</artifactId>
                <version>8.5.0</version>
            </dependency>
           <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13</version>
        <scope>test</scope>
    </dependency>
     <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>5.6.0</version>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.17</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>

            <!-- https://mvnrepository.com/artifact/edu.stanford.nlp/stanford-corenlp -->
            <dependency>
                <groupId>edu.stanford.nlp</groupId>
                <artifactId>stanford-corenlp</artifactId>
                <version>3.9.2</version>
                <scope>provided</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/edu.stanford.nlp/corenlp -->




            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.6.2</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.6</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>2.0.2-beta</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>2.0.2-beta</version>
                <scope>compile</scope>
            </dependency>
       </dependencies>
       </project>

(EDIT)当我使用cmd作为"MVN测试"在Maven中构建PC时

(EDIT)When I do maven build in pc using cmd as "mvn test"

 C:\Users\AP078081\IdeaProjects\npl>mvn test
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for groupId:npl:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.mockito:mockito-all:jar -> duplicate declaration of version 2.0.2-beta @ line 74, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ----------------------------< groupId:npl >-----------------------------
[INFO] Building npl 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ npl ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ npl ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ npl ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\AP078081\IdeaProjects\npl\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ npl ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ npl ---
[INFO] Surefire report directory: C:\Users\AP078081\IdeaProjects\npl\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.053 s
[INFO] Finished at: 2020-03-19T15:53:37+05:30
[INFO] ------------------------------------------------------------------------

我尝试了在StackOverflow以及整个网络上找到的所有可能解决方案.任何帮助,将不胜感激.

I have tried every possible solution found on StackOverflow and all over the web. Any help would be appreciated.

推荐答案

显然,我使用的surefire插件不支持Junit 5.

Apparently, the surefire plugin I was using was not supporting Junit 5.

所以改变这个

<groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.8.1</version>

到最新版本的surefire

To latest version of surefire

<groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M4</version>

这篇关于詹金斯不执行Junit测试类(Maven项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆