How do I specify a separate maven goal for running (Cucumber) acceptance tests?

前端 未结 2 2080
梦如初夏
梦如初夏 2021-02-13 11:21

I have the following project structure:

MyProject
   --src
   --test
      --acceptance
         --step_definitions
         --features
      --unit
2条回答
  •  被撕碎了的回忆
    2021-02-13 12:19

    Is this possible?

    Yes, it is possible. I believe you should separate your unit from the acceptance/integration tests having:

    Slightly modified folders structure for both of these, placing your integration test files in the standard location of src/it:

    MyProject/

    • src/main/java/ (SUT)
    • src/test/ (unit test code)
      • java/
      • resources/
    • src/it/ (acceptance/integration tests)
      • java/ (steps definitions)
      • resources/ (feature files)

    Moreover, by design, different Maven plugins are intended for unit and integration tests:

    • for unit tests: maven-surefire-plugin
    • for acceptance/integration tests: maven-failsafe-plugin

    You must also bind execution of maven-failsafe-pulgin. To run the integration tests separately, you can define a new profile:

    
      
        acceptance-tests
        
          
            
              maven-failsafe-plugin
              2.12
              
                
                  
                    integration-test
                    verify
                  
                
              
            
              
        
      
    
    

    You will also need to configure the plugin to search the src/it directory tree for test cases.

    The acceptance tests can be run afterwards using:

    mvn clean verify -Pacceptance-tests
    

    For complete sample, I'd suggest you to follow http://www.weblogism.com/item/334/integration-tests-with-cucumber-jvm-selenium-and-maven

提交回复
热议问题