Maven 在集成测试之前启动ApacheTomcat服务器
在过去的4天里,我一直在寻找解决方案,并提出了这个问题作为悬赏,但仍然没有得到我的答案 我在pf pom.xml文件的帮助下取得了成功:- a) 使用命令mvntomcat7:run手动启动tomcat服务器。这个命令也 帮助我将war文件部署到tomcat服务器并启动服务器。 b) 在eclipse上使用testng.xml文件配置运行集成测试 其中,我在pf pom.xml文件的帮助下失败:- a) 自动启动tomcat服务器。 b) 运行所有集成测试。 c) 停止tomcat服务器 此问题由我发布,但找不到答案Maven 在集成测试之前启动ApacheTomcat服务器,maven,maven-2,testng,pom.xml,Maven,Maven 2,Testng,Pom.xml,在过去的4天里,我一直在寻找解决方案,并提出了这个问题作为悬赏,但仍然没有得到我的答案 我在pf pom.xml文件的帮助下取得了成功:- a) 使用命令mvntomcat7:run手动启动tomcat服务器。这个命令也 帮助我将war文件部署到tomcat服务器并启动服务器。 b) 在eclipse上使用testng.xml文件配置运行集成测试 其中,我在pf pom.xml文件的帮助下失败:- a) 自动启动tomcat服务器。 b) 运行所有集成测试。 c) 停止tomcat服务器 此问题
请说明我的错误。看起来tomcat的启动和停止绑定到了集成前测试和集成后测试阶段,但是TestNG内容正在测试阶段运行,测试阶段在集成测试阶段之前。正如另一位响应者所说,您应该运行: mvn清理验证-X 。。。因此,您可以通过集成后测试(并捕获用于故障排除的所有调试信息)来跟踪所有阶段,但您还应该将TestNG组件绑定到集成测试阶段。Minimal POM 这里是一个最小的POM文件,我用它来实现你想要的。如果它对你不起作用,请像@BrennaFlood说的那样发布mvn-X clean verify的输出。tomcat7 maven插件和maven故障保护插件的配置分别取自和
<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>org.example</groupId>
<artifactId>tomcat-with-failsafe</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>tomcat7-run</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>tomcat7-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
org.example
带故障保护的tomcat
0.0.1-快照
战争
UTF-8
1.7
1.7
2.2.1
org.testng
testng
6.8.8
测试
org.apache.tomcat.maven
tomcat7 maven插件
2.2
tomcat7跑步
只管打仗
预集成测试
真的
tomcat7关机
关闭
整合后测试
org.apache.maven.plugins
maven故障保护插件
2.17
集成测试
验证
我只想为那些希望使用maven+tomcat7+testng的人添加这一点。基本上,我的场景是,我们的一些IT测试需要运行中的应用程序,以便它们可以发送一些REST调用,但其中一些IT不需要服务器,我将测试用例分为两个不同的套件,一个用于IT,需要服务器位于ServerRequiredIT.xml
中,另一个位于NonServerRequiredIT.xml
中,基于此,我创建了两个配置文件,如下所示
<profiles>
<profile>
<id>run-its</id>
<properties>
<build.profile.id>integration-test</build.profile.id>
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>/</path>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx2048m</argLine>
<printSummary>true</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemProperties>
<property>
<name>log4j.configuration</name>
<value>file:${project.build.testOutputDirectory}/resources/log4j-surefire.properties</value>
</property>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>src/test/scripts/ServerRequiredIT.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>testNG-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx2048m</argLine>
<printSummary>true</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemProperties>
<property>
<name>log4j.configuration</name>
<value>file:${project.build.testOutputDirectory}/resources/log4j-surefire.properties</value>
</property>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>src/test/scripts/NonServerRequiredIT.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
运行
集成测试
假的
真的
org.apache.tomcat.maven
tomcat7 maven插件
2
/
启动雄猫
预集成测试
跑
真的
阻止雄猫
整合后测试
关闭
org.apache.maven.plugins
maven故障保护插件
2.19.1
-Xmx2048m
真的
真的
log4j.配置
文件:${project.build.testOutputDirectory}/resources/log4j-surefire.properties
src/test/scripts/ServerRequiredIT.xml
testNG测试
org.apache.maven.plugins
maven surefire插件
2.19.1
-Xmx2048m
真的
真的
log4j.配置
文件:${project.build.testOutputDirectory}/resources/log4j-surefire.properties
src/test/scripts/NonServerRequiredIT.xml
要运行配置文件,我使用mvn测试-p'nameOfProfile'
。这里重要的是文档中所说的内容
故障保护插件设计用于在
Surefire插件设计用于运行单元测试
希望有帮助