pact-jvm icon indicating copy to clipboard operation
pact-jvm copied to clipboard

[pact-jvm-provider-maven] beforeAll & afterAll

Open ndelacrz opened this issue 7 years ago • 6 comments

Hi, I've been checking the pact-jvm-provider-maven code, and could not see if there is an option to have some sort of a junit-style "@beforeAll" and "@afterAll", where it will execute those steps before and after ALL the pact-verify tests. Is there some way to set that kind of behavior? If not, is there any rationale why not (maybe it's not a good idea, or perhaps there is point against having it?)

ndelacrz avatar Jul 27 '17 12:07 ndelacrz

It's not that it's a bad idea, it is just that nobody has needed this functionality.

If you are using maven, there are other ways of doing this. From the maven documentation at http://maven.apache.org/surefire/maven-failsafe-plugin/:

The Maven lifecycle has four phases for running integration tests:

pre-integration-test for setting up the integration test environment. integration-test for running the integration tests. post-integration-test for tearing down the integration test environment. verify for checking the results of the integration tests.

So if the pact verification is running during the integration-test phase, you can have other plugins run in the pre- and post- phases.

uglyog avatar Aug 02 '17 11:08 uglyog

Hi, sadly this is not possible at the moment. The build ends when the plugin notices pact test failures. So the post-integration-test phase of maven is never called. The pattern which is used by the failsafe plugin, is to have two goals. One goal which is run in the integration-test phase which only produces a test log, but will never fail. And a second goal which will run in the verify phase (comes after post-integration-test) which checks for errors in the log and fails the build.

I want to use the plugin with Spring Boot. I want to start the server in the pre-integration-test and stop it in the post-integration-test phase. The pact plugin fails the build to early so my server is not shut down.

Are you open to accept a pull request for this? What would be your ideas how to implement this?

  • change existing goal completely
  • add two new goals and leave the old one alone
  • add a new verify goal and some property to the original to not fail the build

Danny02 avatar Apr 09 '18 08:04 Danny02

PRs are always welcome, it is what the open source world is built upon!

The best way would be to configuration the Mojo to be able to execute a before and after goal, even if the test fails. I would refer to how the Failsafe Plugin does this for integration tests.

uglyog avatar Apr 11 '18 00:04 uglyog

@uglyog what is your stand on the three choices I lined out in my previous comment?

Danny02 avatar Apr 11 '18 08:04 Danny02

I probably would change the existing goal to support a before and after goal.

uglyog avatar Apr 11 '18 11:04 uglyog

Actually, now that I think about it, two new goals would be better. One that runs the verification and records the results, and one that fails the build if the recorded results indicate a failure. I think that is how the integration plugin works.

uglyog avatar Apr 12 '18 02:04 uglyog