1

Scenario: I am using a cucumberJVM setup using a parallel cucumberJVM plugin which creates separate runner files for every feature file. I want to handle my setup & teardown independently, since cucumberJVM does not support global hooks (or so I'm lead to believe), what is the best way to do this?

Ive tried adding a runListener with junit + maven surefire plugin:

 <properties>
    <property>
    <name>RunListener</name>
    <value>/src/test/java/testRunner/setupTeardown.java</value>
    </property>
</properties>


import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;

public class setupTeardown extends RunListener {

    public void testRunStarted(Description description) throws Exception {

    System.out.println("RUN STARTED ____!!!!");
    }



    public void testRunFinished(Result result) throws Exception {
        System.out.println("Run finished!");

    }

}

Am I making a basic mistake somewhere? I can't seem to get my listener executing the testRunStarted or Finished() methods executing.

0

The solution here was just writing a simple batch file to restore my databases and invoking the batch files via my Jenkins pipeline, using sqlcmd by Microsoft, it was really easily done to set the database state.

Spawning an individual test runner for every scenario left me with nothing to clean up, apart from making sure my browser was properly cleaned up, I took care of this using:

Runtime.getRuntime().addShutdownHook(new Thread(new BrowserCleanup()));

    private static class BrowserCleanup implements Runnable {
    public void run() { 
        try { 
            Driver.webdriver.quit();                
        } catch (NullPointerException e) {
            System.out.println("Browser already shut down.");
        }

    }   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.