Automatically start / stop the web server to test the interface

Now I run separately built-in tomcat via maven:

mvn tomcat7:run 

And then run the mvn test target. My question is, can I configure maven to do this automatically? tomcat must be started before all tests are run, and then stopped.

The following maven configuration is used for the tomcat plugin:

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

+1
source share
1 answer
  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> 
+2
source

Source: https://habr.com/ru/post/1200322/


All Articles