java - AfterAll global hook cucumber-jvm -
i'm using cucumber-jvm
in integration tests , need execute code after scenarios finished, once.
after reading posts this , reviewed reported issue, i've accomplished doing this:
public class contextsteps { private static boolean initialized = false; @cucumber.api.java.before public void setup() throws exception { if (!initialized) { // init context. run once before first scenario starts runtime.getruntime().addshutdownhook(new thread() { @override public void run() { // end context. run once after scenarios finished } }); initialized = true; } } }
i think context initialization (equivalent beforeall
) done in way fine. however, although it's working, i'm not sure @ if afterall
simulation using runtime.getruntime().addshutdownhook()
practice.
so, these questions:
- should avoid
runtime.getruntime().addshutdownhook()
implementafterall
? - are there other better choices emulate
afterall
behaviour in cucumber-jvm?
thanks in advance help.
probably better way use build tool, ant, maven or gradle set-up , tear-down actions, part of integration tests.
when using maven fail safe plug-in, setting integration tests. there phase pre-integration-test
, typically used setting database , launch web-container. integration-tests run (phase integration-test
). , afterwards phase post-integration-test
run, shutting down , closing / removing / cleaning things.
info in case cucumber tests run through junit, following might worth considering
in case simpler, smaller set stuff, can have @ junit @beforeclass , @afterclass. or implement junit @classrule, has it's own before()
, after()
methods.
@classrule public static externalresource resource = new externalresource() { @override protected void before() throws throwable { myserver.connect(); } @override protected void after() { myserver.disconnect(); } };
Comments
Post a Comment