¿Hay alguna manera de ejecutar un método después de que se hayan ejecutado todas las pruebas de pepino?
La anotación @After se ejecutaría después de cada prueba individual, ¿verdad? No quiero algo que solo funcione una vez, sino al final.
Puede usar las anotaciones estándar de JUnit.
En tu clase de corredor, escribe algo similar a esto:
@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"); } }Lo que podría hacer es registrar el controlador de eventos para el evento TestRunFinished . Para eso, puede crear un complemento personalizado que registrará su gancho para este evento:
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 }; }y luego tendrás que registrar el complemento:
-p / --plugin y pasar el nombre completo de la clase Java: your.package.TestEventHandlerPlugin @RunWith(Cucumber.class) @CucumberOptions(plugin = "your.package.TestEventHandlerPlugin") //set features/glue as you need. public class TestRunner { }Con la suite TestNG, las anotaciones también funcionarían.
@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"); }