我使用Spring @IfProfileValue标志识别了许多测试
@IfProfileValue{"a", "c"}
@Test
public void testA{ Do Stuff }
@IfProfileValue{"a", "b"}
@Test
public void testB{ Do Stuff }
@IfProfileValue{"a", "b"}
@Test
public void testC{ Do Stuff }
@IfProfileValue{"b"}
@Test
public void testD{ Do Stuff }
Run Code Online (Sandbox Code Playgroud)
我可以使用运行所有测试
mvm clean install -Dtest-group=a -Dtest-group=b
Run Code Online (Sandbox Code Playgroud)
我想只运行匹配@IfProfileValue = {"a","b")的测试(测试B/C)所以有没有办法只使用maven运行这两个值的交集?
我在Mac 10.9.5上使用Maven 3.2.3并将其用于我的编译器插件...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
<fork>true</fork>
<!-- <compilerId>eclipse</compilerId>-->
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我有我的surefire-plugin配置...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx2048m -XX:MaxPermSize=512M -XX:-UseSplitVerifier ${argLine}</argLine>
<skipTests>${skipAllTests}</skipTests>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是,在运行"mvn clean install"时,我收到此警告......
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option UseSplitVerifier; support was removed in 8.0
Run Code Online (Sandbox Code Playgroud)
什么是Java 8等效的"UseSplitVerifier"?
我在Jenkins中使用Maven 3.2.3,JUnit 4.12和SureFire 2.18.1.我有一个多模块Maven作业设置与以下Maven选项:
clean install -U -e -P qa -Dci -DskipITs
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的Maven构建时,虽然我的一个JUnit测试失败,但Maven模块本身报告"SUCCESS"(后面的输出)......
Executing Maven: -B -f /var/lib/jenkins/workspace/subco/subco/pom.xml clean install -U -e -P qa -Dci -DskipITs
…
———————————————————————————
T E S T S
-------------------------------------------------------
Running org.mainco.subco.user.domain.UserTest
Tests run: 24, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.049 sec <<< FAILURE! - in org.mainco.subco.user.domain.UserTest
testHasRoleNullRoles(org.mainco.subco.user.domain.UserTest) Time elapsed: 0.006 sec <<< FAILURE!
java.lang.AssertionError: Failed to indicate we found right role for user.
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.assertTrue(Assert.java:41)
at
…
[INFO] Tests are …Run Code Online (Sandbox Code Playgroud) 使用mvn clean test命令时是否需要maven surefire插件来运行单元测试?
我阅读了文档并知道它说:
Surefire插件在构建生命周期的测试阶段使用,以执行应用程序的单元测试.它以两种不同的文件格式生成报告:
纯文本文件(.txt)XML文件( .xml)默认情况下,这些文件是在$ {basedir}/target/surefire-reports处生成的.
但是,我在没有使用surefire插件的情况下运行测试,它们都通过了.
我的项目中有一个JUnit测试类,它会逐步更新 - 我每隔几周就会添加一次测试,有时会修改测试代码.
令人惊讶的是,当我使用eclipse JUnit Runner 4运行测试类时,它运行我的旧代码(在更新之前)而不是新代码.我可以更改代码,添加或删除测试,但它仍然运行旧代码.
我试图隔离问题并运行我刚刚编写的单个测试,并且在没有任何堆栈跟踪的情况下得到臭名昭着的"Unrooted tests"错误,以便让我知道问题是什么.
我做了一些研究,根据这里的一些其他线程,很多人遇到了关于JUnit 3\JUnit 4兼容性的这个问题,但这不是这里的情况 - 我注释了我的所有测试,@Test并没有扩展TestCase类.
清理/构建所有eclipse项目都无济于事.但是,当我清理安装我的项目时,这个问题确实有效,但这需要花费太多时间.此外,重命名类(eclipse中的Alt + Shift + R)会立即运行新代码,但将其重命名为原始(和有效)名称,会使旧代码再次运行(WTF?)
帮助将不胜感激,10倍
顾名思义,我正在尝试执行我的Maven项目时生成JUnit结果的HTML报告。有人告诉我要检查maven-surefire-report插件,它看起来像我想要的东西,但似乎无法生成HTML文件。我希望仅生成HTML文件,然后可以将其放入老板的电子邮件中。我并不是真的想将结果发布到网站上(至少目前不是这样)。
这是我的pom部分看起来像的内容(不要担心缺少标签。我正在复制和粘贴相关部分,并尝试不粘贴公司信息,但知道我有正确的开始/结束标签):
编辑:添加了完整的pom。
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myName</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.jtds/jtds -->
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.4.0.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.5</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我可以将参数的值设置forkCount为任何所需的数字,比如12,并且我希望surefirebooter在运行这样的测试时有12个新的Java进程类型.但是ps表明我有时只得到12个预期的Java进程(确切地说:我很少得到它们).相反,我通常会少一些,有时甚至只有三四个.我的数百个单元测试的执行似乎也很慢.
ps在单元测试完成之前,运行进程也经常从输出中消失(我假设终止).在某些情况下,所有这些,然后执行无限期挂起.
文档对此并不太清楚,但我希望在所有单元测试完成之前始终有给定数量的进程.
也许这些surefirebooter过程遇到了一些问题并且过早终止了.但是,我没有看到任何错误消息.我应该在哪里看到它们?我可以打开一些调试日志记录吗?打开Surefire的调试模式改变了测试结果,所以我没有走很远的路径.
我在约400个班级中运行~1600个单元测试,在最好的情况下需要大约7分钟.执行时间差异很大,有时整个事情会在一个多小时后终止.
另一方面,在某些情况下,surefirebooter进程在执行完成(成功)后继续运行并对系统施加大量负载(因此它似乎忙于等待某些事情).
问题:
surefirebooter始终具有所需的进程数.)surefirebooter流程发生情况的消息?(我尝试使用strace但是这也大大改变了行为,以至于呼叫不再终止.)maven-surefire-plugin能够独立运行所有JUnit测试方法吗?即,是否能够为每个测试方法而不是每个测试类分叉JVM?
已弃用的选项
<forkMode>pertest</forkMode>
Run Code Online (Sandbox Code Playgroud)
和当前
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
Run Code Online (Sandbox Code Playgroud)
似乎只为每个测试类分叉.
PS:测试方法应该是独立的,因此没有人需要在新的JVM上运行每一个(而不是说它会非常昂贵).但我想知道是否有这样的选择.
我一起使用maven-surefire-plugin+ Sonar,我想argLine为maven-surefire-plugin的参数添加一些额外的值。
所以我做到了:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<argLine>-DCRR.Webservice.isSimulated=true -D...</argLine>
</configuration>
</plugin>
...
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
但是在这种情况下,我将覆盖argLine参数的原始值,Sonar不会生成jacoco.exec文件。
我可以在Maven调试日志(-X)中看到argLine参数的值是,而没有覆盖它的值-javaagent:/opt/jenkins/.../myproject-SONAR/.repository/org/jacoco/org.jacoco.agent/0.7.4.201502262128/org.jacoco.agent-0.7.4.201502262128-runtime.jar=destfile=/opt/jenkins/.../myproject-SONAR/target/jacoco.exec。
追加此参数原始值的正确方法是什么(保留原始值+添加其他值)?
我正在使用Apache Maven 3.5.0,Java版本:1.8.0_131,供应商:Oracle Corporation。
我有三个模块的多模块Maven项目core,utils以及test-utils
Core具有以下依赖项定义
<dependency>
<groupId>my.project</groupId>
<artifactId>utils</artifactId>
</dependency>
<dependency>
<groupId>my.project</groupId>
<artifactId>test-utils</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我module-info.java为所有三个模块添加了Java 9 定义,它们core看起来像这样:
module my.project.core {
requires my.project.utils;
}
Run Code Online (Sandbox Code Playgroud)
但是我无法弄清楚如何让core测试类能够test-utils在测试执行期间看到类.当maven-surefire-plugin尝试测试运行时,我找不到课程.
如果我添加一个requires my.project.testutils;到core的module-info.java:
module my.project.core {
requires my.project.utils;
requires my.project.testutils; //test dependency
}
Run Code Online (Sandbox Code Playgroud)
然后在编译时我得到一个错误,my.project.testutils模块无法找到(大概是因为它只是作为测试依赖项引入).
如何在Java 9模块化世界中使用测试依赖项?出于显而易见的原因,我不希望我的主代码引入测试依赖项.我错过了什么吗?
java maven java-platform-module-system maven-surefire-plugin java-9