Starting Apache Tomcat Server Before Integration Test

I've searched for a solution in the past 4 days and asked this question as a bounty, but still don't get an answer.

Where I succeeded using the pf pom.xml file: - a) Starting the tomcat server manually using the ie mvn tomcat7: run command. This command also help me deploy my war file to tomcat server and start the server. b) Running my integration tests using testng.xml file configuration on eclipse.

Where I failed with the pf pom.xml file: -

a) Automatic start of tomcat server. b) Running all integration tests. c) Stopping the tomcat server.

This question was posted by me but did not find an answer    Starting apache server before integration testing fails

Please help where I am going wrong.

+3


source to share


3 answers


It looks like you start tomcat and stop getting tied to the pre-integration and post-integration testing stages, but the TestNG stuff is triggered in the testing stage that precedes the integration testing stages. As another respondent said - you should be working:

mvn clean verify -X



... so you catch all the phases through the post-integration-test (and catch all the debug information for troubleshooting), but you should also bind your TestNG components to the integration-test phase.

+1


source


Minimum POM

Here is the minimal POM file I used to achieve what you want. If that doesn't work for you, please mvn -X clean verify

post the output to eg @BrennaFlood. Configs for tomcat7-maven-plugin and maven-failafe-plugin taken from 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 , respectively.



<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>

      

+1


source


I just want to add this for anyone who wants to use maven + tomcat7 + testng. Basically my scenario is that some of our IT tests need a running application to be able to send any kind of REST call, but some of the IT servers do not require a server, I have split the test cases into two different suites for IT requiring server in ServerRequiredIT.xml

and others in NonServerRequiredIT.xml

, based on this I create two profiles as follows.

<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>

      

To run profiles, I use mvn test -P 'nameOfProfile'

. The important thing here is what the documentation says

The Failsafe Plugin is for running integration tests, while the Surefire Plugin is for running unit tests

Hope it helps.

0


source







All Articles