我正在开发一个相当复杂的java项目,它有许多依赖项和许多单元测试.
我在mac(mavericks)上使用java 1.6.0_65,使用maven 3.0.5和maven-surefire-plugin:2.16在几个forks中运行.我的问题是使用多个forks运行此设置会导致fork退出:
"分叉的虚拟机终止了,没有说再见.虚拟机崩溃或System.exit调用?"
只使用一个fork运行它不会产生问题(并且一切都通过)
有一些关于这个问题的信息包括这个StackOverflow问题和这个万无一失的bug(现在似乎已经解决了)
我知道这种情况的"答案"是在我的代码中找到什么叫System.exit() - 我找不到任何东西.
或者是什么原因导致我的JVM崩溃 - 没有hs_pid崩溃报告.
我的问题是我可以用什么样的策略来找到找到这个原因的? 为了澄清,我对上面提到的答案不感兴趣,但是找到它的起源.(或者甚至更好地回答可能造成这种情况的不同答案)
我的Surefire配置是:(但我确实尝试过其他组合)
<parallel>classes</parallel>
<threadCount>1</threadCount>
<forkCount>1C</forkCount>
<reuseForks>false</reuseForks>
<useSystemClassLoader>false</useSystemClassLoader>
<useManifestOnlyJar>true</useManifestOnlyJar>
<useFile>true</useFile>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<runOrder>alphabetical</runOrder>
Run Code Online (Sandbox Code Playgroud)
在使用--debug(-X)运行maven目标后添加#1添加相关的输出
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.16:test (default-test) on project event-logger: ExecutionException; nested exception is java.util.concurrent.ExecutionException: java.lang.RuntimeException: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?
[ERROR] Command was/bin/sh -c cd /Users/nitzan/work/nitzan_5_parallel_tests/event-logger && /Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home/bin/java org.apache.maven.surefire.booter.ForkedBooter /Users/nitzan/work/nitzan_5_parallel_tests/event-logger/target/surefire/surefire5107531798951225850tmp /Users/nitzan/work/nitzan_5_parallel_tests/event-logger/target/surefire/surefire_12561116468761732560tmp
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to …Run Code Online (Sandbox Code Playgroud) 我正在使用maven与JaCoCo插件生成failafe和surefire报告,但我只能设法将它们放在单独的报告中.我想有一个整体覆盖视图(单元测试和集成测试之间的合并).
在我认为彻底的谷歌搜索之后,我只能找到一种方法来与Sonar一起做.有没有更简单的方法来做到这一点?
相关问题:Maven分离单元测试和集成测试
code-coverage maven maven-surefire-plugin maven-failsafe-plugin jacoco
UT =单元测试IT =集成测试.我的所有Integration测试类都使用@Category(IntegrationTest.class)注释
我的目标是:
mvn clean install =>运行UT而不是IT
mvn clean install -DskipTests = true =>不执行任何测试
mvn clean deploy =>运行UT而不是IT
mvn clean test =>运行UT而不是IT
mvn clean verify =>运行UT和IT
mvn clean integration-test =>运行IT并且不执行UT
mvn clean install deploy =>运行UT而不是IT
pom属性:
<junit.version>4.12</junit.version>
<surefire-plugin.version>2.18.1</surefire-plugin.version>
<failsafe-plugin.version>2.18.1</failsafe-plugin.version>
Run Code Online (Sandbox Code Playgroud)
编译:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)单元测试:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<excludedGroups>com.xpto.IntegrationTest</excludedGroups>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)整合测试:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe-plugin.version}</version>
<configuration>
<groups>com.xpto.IntegrationTest</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration> …Run Code Online (Sandbox Code Playgroud)integration-testing maven maven-surefire-plugin maven-failsafe-plugin
我需要根据maven-jar-plugin documentation => http://maven.apache.org/plugins/maven-jar-plugin/usage.html中的这个建议将一些src/test/java移动到src/main/java
我之所以这样做,是因为我在测试范围内的另一个项目中使用了测试(辅助)类.
所以我创建了my-project-test,移动了测试类,并配置了surefire以指定测试类directory =>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testSourceDirectory>${basedir}\src\main\java\</testSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
但是当我启动mvn test时,执行了0次测试=>
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Run Code Online (Sandbox Code Playgroud)
问题与此相同=> Maven没有找到JUnit测试运行但解决方案(配置surefire maven插件)对我不起作用.
我想将我的测试包打包到jar文件中.如何从maven插件Surefire执行生成test-jar.
当使用maven-surefire-plugin并且包含和排除时,它们处理的顺序是什么?此外,如果您有3组测试,第一组是基本集,第二组和第三组是特殊情况,您是否可以使用配置文件进一步包含/排除?如何合并配置文件包含/排除设置?例如,我想做这样的事情:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<excludes>
<exclude>/org/mycompany/dataset/test/ExtractProd*.java</exclude> <!-- requires special network connectivity -->
<exclude>/org/mycompany/dataset/test/LargeDataset*.java</exclude> <!-- requires lengthy processing -->
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>connectedToProdNetwork</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>/org/mycompany/dataset/test/ExtractProd*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>runForAsLongAsYouNeed</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>/org/mycompany/dataset/test/LargeDataset*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
然后能够像这样运行:
mvn package -P connectedToProdNetwork
Run Code Online (Sandbox Code Playgroud)
要么
mvn package -P runForAsLongAsYouNeed
Run Code Online (Sandbox Code Playgroud)
要么
mvn package -P connectedToProdNetwork,runForAsLongAsYouNeed
Run Code Online (Sandbox Code Playgroud)
----更新-----
使用mvn help:effective-pom …
我打算用@Category注释来注释我的一些JUnit4测试.然后我想在我的Maven构建中运行那些类别的测试.
我从Maven文档中看到,可以指定要运行的测试类别.我想知道如何指定一个不运行的测试类别.
谢谢!
我正在使用Maven和多模块.有3个项目.
foo(the parent project)
foo-core
foo-bar
Run Code Online (Sandbox Code Playgroud)
我在foopom中配置所有依赖项和插件:
<modules>
<module>../foo-core</module>
<module>../foo-bar</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
...
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
Run Code Online (Sandbox Code Playgroud)
有几个基类和util类用于单元测试foo-core,所以我添加了maven-jar-pluginin foo-core项目以使其可用于foo-bar:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
当我执行test …
当我使用maven 2运行我的构建时
mvn clean install
Run Code Online (Sandbox Code Playgroud)
我的测试由surefire插件运行.如果测试失败,我会得到以下输出:
Results :
Failed tests:
test1(com.my.MyClassTest)
Tests run: 3, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
Please refer to /home/user/myproject/mymodule/target/surefire-reports for the individual test results.
Run Code Online (Sandbox Code Playgroud)
要获得有关问题的详细信息,我必须查看surefire报告文件夹.每次我的测试失败时这样做会变得很烦人.有什么方法可以在stdout上获取这些细节(断言消息+异常+堆栈跟踪)吗?
我在运行~300 JUnit测试并使用Spring上下文时看到'java.lang.OutOfMemoryError:PermGen space'.从那时起,我很难搞清楚PermGen吃了什么东西:
-XX:+TraceClassLoading和-XX:+TraceClassUnloading启用后,我会在执行最后20-30次测试之前看到没有其他"加载"事件OutOfMemoryError.后者似乎表明除了Class对象之外的东西正在填充PermGen,不是吗?如果是这样,它会是什么?例如,是否存在类实例存储在PermGen中的情况?
这是我的VM信息:
$ java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
Run Code Online (Sandbox Code Playgroud)
有关
FWIW,我的问题的根源促成了这篇文章,结果有些微不足道:我假设Maven Surefire插件在MAfor_OPTS(或运行mvn的虚拟机实例)的情况下从虚拟机中继承VM设置 - 它没有(boo).必须在插件的配置中明确指定使用argLine的那些.HTH.