How to run tests after deployment using Maven?

后端 未结 2 1507
余生分开走
余生分开走 2021-02-09 17:10

I\'m trying to decide how to create a set of Acceptance Tests for a Java-EE web application.

Here\'s the setup: Maven is used to generate a WAR file and deploy it into

相关标签:
2条回答
  • 2021-02-09 17:24

    If you really need to do stuff after deployment, then you can either run failsafe, and by implication JUnit) as part of the deploy phase.

    What I usually do, if to have seperate module. So, you can have one maven project, which contains your project and a separate 'deployment test' project. Then, building the parent project will build and run your war and then run the deployment tests. You can use junit as normal.

    The second fits better into jenkins because you'll still have a single project as well.

    0 讨论(0)
  • 2021-02-09 17:38

    Just because that phase is called deploy doesn't mean that you have to use it for deploying your application for testing. In fact, it should only be used for "deploying" the artifact to a maven repository. Read through the description of the Maven lifecycle phases and you'll see that there are some phases dedicated to your use case:

    pre-integration-test
    integration-test
    post-integration-test  
    

    Have a look at the Cargo Maven plugin. It's made to deploy your WAR file to various containers for testing. They definitely show demos of use cases like the one you describe on your site. I would expect that ultimately, you can be using Cargo to deploy to your container ( from one of the earlier phases like pre-integration-test )

    Note, Jenkins also has a plugin that is a wrapper around the Cargo plugin. So you might do what you need via Jenkins. Also note, you don't need to run your Jenkins build job as mvn clean deploy. You could have one build job that just runs the integration tests, and fires another "deploy" job only when it succeeds.

    0 讨论(0)
提交回复
热议问题