Search code examples
maventestingweblogic

run junit tests on war file before deploying to weblogic


I have some junit test cases which tests RESTful web services. I'm using maven to build war. How to run these RESTful web services test cases on war file which is generated by maven before deploying it to the weblogic application server. please help.


Solution

  • You can use the pre-integration-test, integration-test and post-integration-test phase to start an servlet engine like jetty/tomcat etc. and afterwards run your integration tests via maven-failsafe-plugin against your service. You need to name the tests accordingly.

    <project>
      [...]
      <build>
        [...]
        <plugins>
          [...]
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.17</version>
            <executions>
              <execution>
                <id>integration-test</id>
                <goals>
                  <goal>integration-test</goal>
                </goals>
              </execution>
              <execution>
                <id>verify</id>
                <goals>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
    

    In the docs of maven-failsafe-plugin you will find also an example to start jetty ...