gpt4 book ai didi

java - jenkins maven build 不运行 JUnit 测试

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:56:27 25 4
gpt4 key购买 nike

我有完全相同的代码,只是以两种不同的方式编译。一个是 Spring 中的 maven 构建,另一个是 Jenkins 中的 maven 构建。

Spring 构建产生

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestApplication 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Woof ---
[INFO] Deleting TestApplication\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Woof ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ Woof ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 7 source files to TestApplication\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Woof ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ Woof ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Woof ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ Woof ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to TestApplication\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Woof ---
[INFO] Surefire report directory: TestApplication\target\surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.woof.bark.TestTest
Tests run: 5, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.667 sec <<< FAILURE!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

但是 Jenkins 构建产生了

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building TestApplication 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Woof ---
[INFO] Deleting TestApplication\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Woof ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ Woof ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 7 source files to TestApplication\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Woof ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ Woof ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Woof ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ Woof ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to TestApplication\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Woof ---
[INFO] Surefire report directory: TestApplication\target\surefire-reports
[JENKINS] Recording test results
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
Finished: SUCCESS

我如何让 Jenkins 也运行单元测试并在案例失败时停止构建?

添加 MAVEN_OPTS -DskipTests=false -Dmaven.test.failure.ignore=false 不起作用。

最佳答案

原来我在我的 POM.xml 中缺少一个插件

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

关于java - jenkins maven build 不运行 JUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34097274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com