symon
symon

Reputation: 650

Running code only once during maven forked process execution?

Scenario: I am running a lot of test automation using cucumberJVM and maven, forked processes. I want to run something only once, how can I achieve this? obviously any sort of global before all hook for cucumber (or similar work around) would run on every forked process initially, e.g consider before ALL my forked processes are executing tests I wanted to restore a database (trivial example) using a @before hook with a runOnce boolean would run on every single fork regardless, I guess I am not quite sure on when the forking occurs and how to intercept and run code before that?

Could someone recommend me a nice solution to this?

Thank you for your time.

Upvotes: 0

Views: 87

Answers (1)

user944849
user944849

Reputation: 14951

The Maven lifecycle might help here. Note the pre-integration-test phase. You could find plugins that do the kind of set up needed (database setup, starting Tomcat, etc), and bind executions of the plugin(s) to that phase. Then use the maven-failsafe-plugin to execute the tests. There's a post-integration-test phase that allows for tearing down the environment, and a separate verify phase for checking the results.

The Failsafe plugin docs give a decent overview. Since you plan to run parallel tests, I suggest paying particular attention to those sections/config options.

Upvotes: 1

Related Questions