question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add @BeforeAll and @AfterAll hooks

See original GitHub issue

People keep asking for BeforeAll and AfterAll hooks. I haven’t had a big need for them myself, but it seems to me this would be sufficient:

public class GlobalHooks {
    private static boolean dunit = false;

    @Before
    public void beforeAll() {
        if(!dunit) {
            Runtime.getRuntime().addShutdownHook(afterAllThread);
            // do the beforeAll stuff...
            dunit = true;
        }
    }
}

If this doesn’t cut it for you, please explain in this ticket, and maybe we’ll add special support for it.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:133
  • Comments:128 (32 by maintainers)

github_iconTop GitHub Comments

29reactions
mikquinlancommented, Jun 1, 2013

Any movement on this issue? I’d love to have it. Of course, I’m just one person. 😉

24reactions
wjpowellcommented, Aug 3, 2013

You don’t need to do this in cucumber. Use the @BeforeClass and @AfterClass annotation from within the JUnit test used to run the cucumber tests. This has the benefit of running only for the features specified by the paths or tags options.

@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");
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting @BeforeAll and @AfterAll behaviour with Cucumber ...
The corresponding github issue 515 about adding @BeforeAll and @AfterAll hooks is highly popular. It obviously struck a nerve.
Read more >
Cucumber Before All and After All Hooks - ProgramsBuzz
In Cucumber version 7.0.0, Before All and After All, Hooks are implemented. BeforeAll run before any scenario is run, and AfterAll run after...
Read more >
Global BeforeAll Hook for cucumber-jvm? - java - Stack Overflow
Use the hooks of your test framework: @BeforeAll and @AfterAll for JUnit 5,; @BeforeClass and @AfterClass for JUnit 4.
Read more >
BeforeAll and AfterAll workaround for cucumber-java
Dependencies. Add the following cucumber dependencies to your project: · CucumberHooks implements ConcurrentEventListener. Create a new class ...
Read more >
Cucumber Hooks - Baeldung
3. Hooks · 3.1. @Before · 3.2. @BeforeStep · 3.3. @AfterStep · 3.4. @After · 3.5. The Scenario Parameter.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found