How to run UnitTests in maven which is in src/test-integration/java folder

后端 未结 2 1018
清酒与你
清酒与你 2020-12-14 08:12

When we say mvn test, usual way is that maven will look for the tests present in src/test/java folder. But I have my tests in some different folder, namely src/integration-t

2条回答
  •  孤城傲影
    2020-12-14 08:28

    First you shouldn't run those integration test via the test life cycle, cause pre-integration-test, integration-test and post-integration-test life cycle phase exist. Apart from that for integration tests the maven-failsafe-plugin is responsible.

    There are several options to handle your situations. First you should follow the naming conventions for integration tests

    
     **/IT*.java
     **/*IT.java
     **/*ITCase.java
    
    

    which means to put the integration tests into the default folder src/test/java. If you have a multi-module build it would be the best having a separate module which contains the integration-tests only or you can go the path you decided to use a separate folder (which is not the best):

    First you need to add the folder using the buildhelper-maven-plugin to get those integration tests being compiled like this:

      
        org.codehaus.mojo
        build-helper-maven-plugin
        1.9.1
        
          
            add-test-source
            process-resources
            
              add-test-source
            
            
              
                src/integration-test/java
              
            
          
        
      
    

    and you have to configuration the maven-failsafe-plugin like this:

    
      [...]
      
        
          
            org.apache.maven.plugins
            maven-failsafe-plugin
            2.14.1
            
              
                
                  integration-test
                  verify
                
              
            
          
        
      
      [...]
    
    

    After you have configured you can run your integration tests via:

    mvn verify
    

提交回复
热议问题