Discussion:
[Cucumber] [JVM] AfterAll hook works like @After
(too old to reply)
Denis Veselovskiy
2017-09-26 12:28:56 UTC
Permalink
Raw Message
Hi, guys

I'm trying to do BeforeAll and AfterAll at Java and faced some problems.

Here is my Java code:

import cucumber.api.java.Before;

private static boolean SUITE_TRIGGER = false;


@Before
public void setUp(final Scenario scenario) {
if (!SUITE_TRIGGER) {
SUITE_TRIGGER = true;
readProperties();
BaseApiTest.initApiClient();
RestUtil.createDefaultCampaign();
addShutdownHook();
}
}

public void addShutdownHook(){
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
System.out.println(CAMPAIGN_ID);
RestUtil.deleteDefaultCampaign();
}
});
}


The problem is next:
createDefaultCampaign() works fine - 1 time per test suite
but deleteDefaultCampaign() - executes after each scenario ((

I was googling a lot and couldn't find workable solution for my problem. I
even have found that long ago there was a pull request implementing this
functionality - but than it was reverted (

Could you give me advice please? How to resolve this??

Many thanks in any case)
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
MP Korstanje
2017-09-27 18:11:27 UTC
Permalink
Raw Message
Hey Denis,

your code looks okay. Try running it in the debugger and see who is
actually calling `deleteDefaultCampaign`.

Or if you are using JUnit considering using JUnits @BeforeClass and
@AfterClass hooks.

-MP.


@RunWith(Cucumber.class)
public class Test {
@BeforeClass
public static void before {
// Do stuff
}

@AfterClass
public static void after {
// Do stuff
}
}
Post by Denis Veselovskiy
Hi, guys
I'm trying to do BeforeAll and AfterAll at Java and faced some problems.
import cucumber.api.java.Before;
private static boolean SUITE_TRIGGER = false;
@Before
public void setUp(final Scenario scenario) {
if (!SUITE_TRIGGER) {
SUITE_TRIGGER = true;
readProperties();
BaseApiTest.initApiClient();
RestUtil.createDefaultCampaign();
addShutdownHook();
}
}
public void addShutdownHook(){
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
System.out.println(CAMPAIGN_ID);
RestUtil.deleteDefaultCampaign();
}
});
}
createDefaultCampaign() works fine - 1 time per test suite
but deleteDefaultCampaign() - executes after each scenario ((
I was googling a lot and couldn't find workable solution for my problem. I
even have found that long ago there was a pull request implementing this
functionality - but than it was reverted (
Could you give me advice please? How to resolve this??
Many thanks in any case)
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...