Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda