我正在尝试使用Maven Failsafe插件来运行此配置的集成测试:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.7.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.7</version>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>3600000</maxIdleTime>
</connector>
</connectors>
<contextPath>/</contextPath>
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargetPatterns>
<scanTargetPattern>
<directory>src/main/webapp/WEB-INF</directory>
<excludes>
<exclude>**/*.jsp</exclude>
<exclude>**/*.html</exclude>
</excludes>
<includes>
<include>**/*.page</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</scanTargetPattern>
</scanTargetPatterns>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
一切都很好,直到Jetty在预集成测试阶段开始.然后没有任何事情发生,好像在等待什么.最后一行说:
[INFO] Started Jetty Server
如何让测试在之后开始?我用maven运行maven mvn verify.
我目前正在使用 Maven Failsafe 插件来分叉执行测试(在单独的 JVM 中并行运行多个测试)。
我根据机器的核心数量手动设置forkCount变量,但我希望 Maven 自动确定该变量,这样我最终可以得到如下结果:
<forkCount>${system.numCores}</forkCount>
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我有一个JUnit集成测试,在Maven Failsafe插件执行时无法抛出异常.我配置了failsafe来将系统写入特定于测试的文件(redirectTestOutputToFile = true).但是该文件和XML测试结果文件都不包含异常的完整堆栈跟踪.在大多数情况下,有趣的东西是在引起链的末尾.
是否有可能以某种方式配置故障保护以记录完整的堆栈跟踪?
当然,可以使用try-catch围绕测试本身并手动记录堆栈跟踪,但这会产生大量的样板代码.
请注意:这个问题不是指surefire,而是故障安全,并已相应标记.它没有询问如何在控制台中显示堆栈跟踪,但如何使故障保护将完整的堆栈跟踪保存到文件而不仅仅是部分文件.这个答案很有用,因为它命名了正确的属性,但它并不完全正确,因为当然必须将配置应用于故障保护,而不是确定.此外,问题2928548的公认答案对于这个问题是明确错误的.
我有一个基于spring-boot的应用程序,并且pom.xml文件配置如下。
<?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>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> …Run Code Online (Sandbox Code Playgroud) java integration-testing maven-failsafe-plugin spring-boot spring-boot-maven-plugin
我试图通过maven命令分离单元测试和集成测试。
pom.xml
....
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Fast*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
这是我的整合测试
@RunWith(SpringRunner.class)
@SpringBootTest(classes = StudentApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class StudentControllerIT {
...
Run Code Online (Sandbox Code Playgroud)
这是单元测试
@RunWith(SpringRunner.class)
@WebMvcTest(value = StudentController.class, secure = false)
public class StudentFastControllerTest {
....
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试运行命令时,mvn test仅 StudentFastControllerTest执行测试,但是当我运行命令mvn integration-test或mvn verify同时执行两个测试类而不是仅执行时StudentControllerIT。
尝试重新访问在Maven中的Junit 5平台(5.3.2)下运行的Junit 5/4集成测试。从 如何运行JUnit 4和JUnit的混合5次试验中使用并联的行家故障安全-插件
在surefire插件2.22.1下运行单元测试可以同时在JUnit 5和JUnit 4的并行测试和混合测试中工作,并且可以看到工作线程的详细信息。
尝试在故障安全2.22.1中执行相同的操作,但是需要花费日志时间,并且似乎没有并行执行。另外,仅[main](详细)打印,没有工作线程。
故障保险是否支持Junit 5平台中的线程/并发执行?如果是这样,如何?
我也使用config params:
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=6
Run Code Online (Sandbox Code Playgroud) 我想访问存储在 jar 文件中的实现版本等信息。这似乎工作得很好,在任何技术中,但总是基于类加载器。
如果我想在我的 maven 环境中测试,当然我不能使用 surefire 插件,因为这是在 jar 中打包之前。因此我必须使用故障安全插件。
但是这两种技术都不起作用,很可能是因为一些关于类加载器的黑魔法。
获取实现版本的最简单方法就是
this.getClass().getPackage().getImplementationVersion()
Run Code Online (Sandbox Code Playgroud)
它从META-INF/MANIFEST.MF看起来像的罐子里读取
Name: eu/simuline/octave/
Extension-name: eu.simuline.octave
Specification-Version: 0.7
Implementation-Version: 0.7-SNAPSHOT
Run Code Online (Sandbox Code Playgroud)
也许不需要扩展,需要的是部分名称,它以一种明显的方式从包名称派生出来(尾部斜杠似乎很重要;-))。但如前所述,这仅适用于生产环境,不适用于带有故障安全插件的测试。然后java代码返回0.7-SNAPSHOT,否则它只是返回null,这意味着根据api文档,版本未知......好吧。
我该怎么做才能在 maven 测试中包含元信息???
我想知道我的集成测试是否会按特定顺序运行并查看maven-failsafe-plugin 文档,这是
runOrder:定义测试运行的顺序。支持的值是“alphabetical”、“reversealphabetical”、“random”、“hourly”(偶数小时的字母顺序,奇数小时的字母顺序相反)、“failedfirst”、“balanced”和“文件系统”。每小时的奇数/偶数是在扫描类路径时确定的,这意味着它可能会在多模块构建期间发生变化。Failed first 将首先运行上次运行失败的测试,以及这次运行的新测试。Balanced 仅与 parallel=classes 相关,并且会尝试优化测试的运行顺序,使所有测试同时完成,从而减少整体执行时间。请注意,统计信息存储在 pom.xml 旁边的名为 .surefire-XXXXXXXXX 的文件中,并且不应签入版本控制。“XXXXX”是整个surefire配置的SHA1校验和,因此不同的配置会有不同的统计文件,这意味着如果您更改任何配置设置,您将在建立新的统计数据之前重新运行一次。
- 类型:
java.lang.String- 自从:
2.7- 必需的:
No- 默认:
filesystem
文件系统顺序是什么意思?创建文件的顺序?
我正在尝试使用 Junit Jupiter 和 Junit Vintage 包在混合 JUnit 4 和 JUnit 5 中运行并行集成测试,并在最新的 maven-failsafe-plugin 依赖项中添加 junit 5 的 Surefire 插件。
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
所有测试都运行,但不是并行的,需要花费很多时间。如果我不添加此依赖项,它不会选择并运行 Junit 5 测试,而是并行运行其他测试,它是在插件中配置的。
没有使用 Junit 5 的故障安全插件的官方文档。有没有办法并行运行测试?
编辑:记录器写入添加此依赖项时不使用线程(仅主线程)。
编辑:我只是想澄清一下,为了提出一个有已知、客观答案的问题,这个问题是,“Killing self fork JVM。PING timeout elapsed”实际上意味着什么,例如 ping 是什么,以及为什么failsafe决定它应该退出测试过程?由于这是 StackOverflow,因此请不要回复修复某些虚拟机退出的建议,尤其是那些导致与我们下面看到的行为不同的建议。例如,控制台中没有 OutOfMemoryError,因此我认为虚拟机没有耗尽堆空间。如果您确实这样回答,SO 管理员可能会误解我的问题并锁定或关闭它。
我们有时会在 CI 构建中遇到虚拟机崩溃的情况,例如:
[INFO] Results:
[INFO]
[WARNING] Tests run: 8152, Failures: 0, Errors: 0, Skipped: 31
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.22.1:verify (integration-test) on project app_server: There are test failures.
[ERROR]
[ERROR] Please refer to /builds/App/Development/App/app_server/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit …Run Code Online (Sandbox Code Playgroud)