Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Run after all cucumber tests

Is there a way to run a method after all of the cucumber tests have been run?

The @After annotation would run after every individual test, right? I wan't something that would only run once, but at the very end.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You could use the standard JUnit annotations.

In your runner class write something similar to this:

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"html:target/cucumber-html-report", "json-pretty:target/cucumber-json-report.json"})
public class RunCukesTest {

    @BeforeClass
    public static void setup() {
        System.out.println("Ran the before");
    }

    @AfterClass
    public static void teardown() {
        System.out.println("Ran the after");
    }
}
about 4 years ago · Santiago Trujillo Report

0

What you could do is to register event handler for TestRunFinished event. For that you can create a custom plugin which will register your hook for this event :

public class TestEventHandlerPlugin implements ConcurrentEventListener {

    @Override
    public void setEventPublisher(EventPublisher eventPublisher) {
        eventPublisher.registerHandlerFor(TestRunFinished.class, teardown);
    }

    private EventHandler<TestRunFinished> teardown = event -> {
        //run code after all tests
    };
}

and then you will have to register the plugin :

  • if you are running cucumber CLI you can use -p/--plugin option and pass fully qualified name of the java class : your.package.TestEventHandlerPlugin
  • for Junit runner :
@RunWith(Cucumber.class)
@CucumberOptions(plugin = "your.package.TestEventHandlerPlugin") //set features/glue as you need.
public class TestRunner {

}
about 4 years ago · Santiago Trujillo Report

0

With TestNG suite annotations would work as well.

@BeforeSuite
public static void setup() {
    System.out.println("Ran once the before all the tests");
}

@AfterSuite
public static void cleanup() {
    System.out.println("Ran once the after all the tests");
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!