Howto add another test source folder to Maven and compile it to a separate folder?

后端 未结 3 362
自闭症患者
自闭症患者 2020-12-09 07:17

I have the default src/test/java folder for our unit tests. A separate folder src/integration/java is available for the integration tests.

3条回答
  •  抹茶落季
    2020-12-09 08:19

    Based what you've written it sounds like you didn't named your integration tests correctly and you didn't use the maven-failsafe-plugin for your integration tests. Based on the convention of the maven-failsafe-plugin you should name your integration tests like *IT.java. If you named your integration tests appropriately you can handle that with a more or less configuration like this:

    
      [...]
      
        [...]
         
            org.codehaus.mojo
            build-helper-maven-plugin
            1.9.1
            
              
                add-test-source
                generate-test-sources
                
                  add-test-source
                
                
                  
                    src/integration/java
                  
                
              
            
          
          [...]
      
      [...]
    
    

    With the above it's possible to hold the integration tests within the same module. But this will not solve the idea of having the compiled integration tests classes into a separate folder.

    Sometimes it's better to have a separate integration test module which contains only the integration tests (which results in having a multi-module build). If you like to leave the conventions of Maven you can try to configure the maven-compiler-plugin to use a different output path (eg. target/integration-tests/classes) which don't think will really work.

提交回复
热议问题