Maven - deploy webapp to tomcat before JUnit test

后端 未结 3 1052
一整个雨季
一整个雨季 2020-12-12 13:07

I have webapp which provides web service. I want to perform JUnit tests with SoapUI to check if this service is working properly.
But to test web service application has

3条回答
  •  余生分开走
    2020-12-12 13:57

    As Stephen Connolly explains there is no a direct way to configure this. I will explain how to solve this using failsafe plugin. In the maven lifecycle type of test can be tested. Unit testing one of them and another one is integrate testing. Unit testing can be run in the test stage of maven lifecycle. When you want to do integrate test it can be done in verify stage. If you want to know the difference between unit testing and integrate testing, this is a good one. By default unit test classes should be in ***/*Test.java, and **/*TestCase.java this format. The failsafe plugin will look for **/IT*.java, **/*IT.java, and **/*ITCase.java.

    Here is an example.

    Here I have one unit test class and one integrate test class. Now I will explain, how should be the looks like maven pom.xml. Build section of maven configuration should look like this.

    
        
            
                maven-war-plugin
                2.3
                
                    src/main/webapp/WEB-INF/web.xml
                    ${name}
                    /home/jobs/wso2/wso2as-5.3.0/repository/deployment/server/webapps
                    
                    
                
            
    
            
                maven-compiler-plugin
                3.1
                
                    1.7
                    1.7
                
            
    
            
                org.apache.maven.plugins
                maven-failsafe-plugin
                2.12.4
                
                    
                        integration-test
                        
                            integration-test
                            verify
                        
                    
                
            
        
    

    Unit tests are run before deploying the web app(war file). But integrate tests are run in verify stage. I hope your requirement is satisfied in this stage.

提交回复
热议问题