集成测试前启动 Apache tomcat 服务器

2023-12-01

过去 4 天我一直在寻找解决方案,并作为赏金提出了这个问题,但仍然没有得到答案。

我在 pf pom.xml 文件的帮助下取得了成功:- a) 使用命令手动启动 tomcat 服务器,即 mvn tomcat7:run。该命令还 帮助我将 war 文件部署到 tomcat 服务器并启动服务器。 b) 在 Eclipse 上使用 testng.xml 文件配置运行我的集成测试。

我在 pf pom.xml 文件的帮助下失败了:-

a) 自动启动tomcat服务器。 b) 运行所有集成测试。 c) 停止 tomcat 服务器。

这个问题是我发的,但是找不到答案在集成测试之前启动 apache 服务器不起作用

请帮助我哪里错了。


最小聚甲醛

这是一个最小的 POM 文件,我用它来实现你想要的。如果它不适合您,请发布输出mvn -X clean verify就像@BrennaFlood 说的。 tomcat7-maven-plugin 和 maven-failsafe-plugin 的配置取自http://tomcat.apache.org/maven-plugin-2.2/run-mojo-features.html#Use_it_with_selenium_mojo and http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html, 分别。

<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

集成测试前启动 Apache tomcat 服务器 的相关文章

随机推荐