Automatically starting/stopping web server for frontend tests
Asked Answered
D

1

3

Now, I start separately embedded tomcat via maven:

mvn tomcat7:run

And then run the mvn test goal. My question is can I configure maven in order to do that automatically? tomcat has to be started before all tests run, and then stopped.

The following maven configuration for tomcat plugin is used:

        <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <path>/SpringMvcExample</path>
                <url>http://localhost:8080/manager/text</url>
                <server>tomcat7</server>
            </configuration>
        </plugin>
    </plugins>

I've tried to update the plugin configuration to:

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <configuration>
            <path>/SpringMvcExample</path>
            <url>http://localhost:8080/manager/text</url>
            <server>tomcat7</server>
        </configuration>
        <executions>
            <execution>
                <id>start-tomcat</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
            <execution>
                <id>stop-tomcat</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>shutdown</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

But it did not help

Distrust answered 10/11, 2013 at 6:6 Comment(0)
B
4
        attach tomcat:run to pre-integration-test
        attach tomcat:shutdown to post-integration-test
Below is the code snippet. 
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
       <executions>
          <execution>
            <id>tomcat-run</id>
            <goals>
              <goal>run-war-only</goal>
            </goals>
            <phase>pre-integration-test</phase>
                <configuration>

                    <fork>true</fork> 
                </configuration>

           </execution>
           <execution>
            <id>tomcat-shutdown</id>
            <goals>
              <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
          </execution>
        </executions>
      </plugin>
Blackwood answered 10/11, 2013 at 6:37 Comment(2)
please specify where to put these statements?Distrust
A couple of questions. Which maven version do you use? in the configuration - url and server are red in my editor and it seems element is not allowed here. and the second one: how to specify that test is integration? The name of class that is used: SimpleViewControllerSeleniumTestDistrust

© 2022 - 2024 — McMap. All rights reserved.