我的Jenkins作业有以下配置:首先清理并构建maven项目,然后运行单元测试和静态分析:clean install sonar:sonar
问题在于install,sonar:sonar每个都运行单元测试,这有效地使构建时间加倍.
我通过改变固定此clean install sonar:sonar于clean install -DskipTests和使用詹金斯声纳插件运行声纳.现在单元测试只运行一次,声纳显示结果,但Jenkins不再知道测试了.
我的猜测是Jenkins只是在构建之后查看surefire-reports文件夹,而不是在Sonar之后(这是一个构建后的动作).
有没有人能够从Maven构建的JaCoCo中获得JMockit和Powermock单元测试的单元测试覆盖率?
我有一个Powermock单元测试的现有测试集,我想逐步迁移到JMockit.但我需要能够在一份报告中看到所有单元测试的测试覆盖率,最好是在Sonar中.
通过将JaCoCo置于"离线"模式,我确实让JMockit和Powermock测试与Surefire/JaCoCo一起运行(否则我遇到了一个问题,其中一个代理在测试结束时没有被终止,然后mvn clean无法删除在下次运行时生成目标\ surefire\surefirebooter2967126910681005991.jar).但是没有为JMockit测试生成覆盖范围.
如果你有这个工作,请发布你的pom的一些摘录.
这就是我的pom的样子(注意surefire插件与reuseForks = false一致,以解决Powermock中的PermGen内存泄漏问题,这是迁移到JMockit的主要原因之一)
<profile>
<!-- use this profile to perform Sonar analysis -->
<id>sonar</id>
<properties>
<sonar.language>java</sonar.language>
<!-- Tells Sonar to use the generated test coverage report -->
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<!-- Tells Sonar to use JaCoCo as the code coverage tool -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
</properties>
<build>
<plugins>
<!-- surefire (junit) plugin config with JaCoCo listener -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<!-- note: use single JVM to append …Run Code Online (Sandbox Code Playgroud) 我想在我的项目上运行mvn test.项目本身编译和安装,但man测试失败,输出如下:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test (default-test) on project udms-server: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test failed: There was an error in the forked process
[ERROR] java.lang.UnsupportedClassVersionError: some/project/Event : Unsupported major.minor version 52.0
[ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
[ERROR] at java.lang.ClassLoader.defineClass(Unknown Source)
[ERROR] at java.security.SecureClassLoader.defineClass(Unknown Source)
[ERROR] at java.net.URLClassLoader.defineClass(Unknown Source)
[ERROR] at java.net.URLClassLoader.access$100(Unknown Source)
[ERROR] at java.net.URLClassLoader$1.run(Unknown Source)
[ERROR] at java.net.URLClassLoader$1.run(Unknown Source)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(Unknown Source)
[ERROR] at java.lang.ClassLoader.loadClass(Unknown Source)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[ERROR] at …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JaCoCo为代码覆盖添加报告生成.该项目正在使用Maven,所以我有jacoco maven插件配置如下:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.maven.plugin.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<outputDirectory>${basedir}/target/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
还有像这样的surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>${argLine} -XX:-UseSplitVerifier</argLine>
<printSummary>true</printSummary>
<excludes>
<exclude>**/selenium/**/*.java</exclude>
<excludes>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是在跑步结束时
mvn清洁包
我收到这样的错误:
[错误]无法执行目标org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:项目LMS上的报告(报告):JaCoCo测试报告生成中发生错误.创建报告时出错:无效的文字/长度代码 - > [帮助1] [错误] [错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven.[ERROR]使用-X开关重新运行Maven以启用完整的调试日志记录.[错误] [错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:[错误] [帮助1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
问题是,在另一个项目中,同样的事情就像一个魅力.我在网上找不到解决方案.有人有什么想法吗?
使用-e开关我收到以下错误:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:report (report) on project LMS: An error has occurred in JaCoCo Test report generation.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) …Run Code Online (Sandbox Code Playgroud) 在我的万无一失的配置中,我有一个classpathDependencyExcludes条目.
出于某种原因,Intellij似乎没有采用这种配置(mvn test,确实如此).有没有办法让Intellij注意到我的冲浪配置?
PS.好像很久很久以前在Intellij(IDEA-52286)报道了类似的东西,但从未修复过.
我想RunListener在单元测试中使用我自己的。所以我创建了以下类:
public class MyRunListener extends RunListener {
public MyRunListener() {
System.out.println("Creation of Run Listener...");
}
@Override
public void testStarted(Description description) throws Exception {
System.out.println("A Test is going to start");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,在我的pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>listener</name>
<value>my.company.MyRunListener</value>
</property>
</properties>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
现在,当我mvn test在项目中运行时,输出如下:
Creation of Run Listener...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running xxx.SomeNewTests
Test New #1
Test New #2
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, …Run Code Online (Sandbox Code Playgroud) 我有一个 Maven 项目,我正在使用 Surefire-plugin 来运行我的测试。以前,我没有强制使用任何版本,maven 为我选择了 2.4.3(为什么??)。
我想改用 2.7.2,它对 JUnit4 有更好的支持(尤其是参数化测试)。
因此,我修改了根父 POM,如下所示:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.7.2</version>
</dependency>
</dependencies>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Run Code Online (Sandbox Code Playgroud)
然而,在子模块中,surefire:2.4.3 不断被调用。这是 -X 调试跟踪:
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test'
Run Code Online (Sandbox Code Playgroud)
而在父 pom 中,使用 2.7.2:
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.7.2:test'
Run Code Online (Sandbox Code Playgroud)
甚至 effective-pom 显示插件的“版本”如果没有在子模块中继承:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激。
问候,拉斐尔
我希望 Maven 在遇到第一个错误时停止尝试运行我的 JUnit Spring 测试。这可能吗?
我的测试类如下所示,我将它们作为标准 Maven 目标运行。
@ContextConfiguration(locations = {"classpath:/spring-config/store-persistence.xml","classpath:/spring-config/store-security.xml","classpath:/spring-config/store-service.xml", "classpath:/spring-config/store-servlet.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
public class SkuLicenceServiceIntegrationTest
{
...
Run Code Online (Sandbox Code Playgroud)
如果 Spring 配置中存在错误,则每个测试都会尝试重新启动 Spring 上下文,这每次需要 20 秒。这意味着我们很长时间都没有发现任何测试失败,因为它会在得出构建失败的结论之前尝试运行全部测试!
我创建了一个 Maven 项目来测试我的应用程序。我在我的项目中使用了Webdriver、TestNG框架。我使用了 maven Surefire 插件和 reporty-ng 插件来生成测试用例的报告。当我使用命令( mvn 测试站点)在 IDE ( eclipse ) 或命令提示符中运行时,这工作正常。现在我必须将其制作为 jar 文件,以便我可以将该 jar 文件放入任何系统中并运行它。
那么问题来了:
那么我将如何运行该 jar 文件呢?
我使用 Maven Surefire 插件来运行一组特定的测试。例如:
package suite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import suite.slow.EvenSlowerClassTest;
import suite.slow.SlowClassTest;
@RunWith(Suite.class)
@Suite.SuiteClasses({
SlowClassTest.class,
EvenSlowerClassTest.class
})
public class SlowSuite {
}
Run Code Online (Sandbox Code Playgroud)
通过使用maven命令
test -DrunSuite=**/FastSuite.class -DfailIfNoTests=false
Run Code Online (Sandbox Code Playgroud)
我可以显式运行 FastSuite 或 SlowSuite 测试套件,但是,如何运行我拥有的所有测试套件或测试套件中未涵盖的所有测试?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>${runSuite}</include>
</includes>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)