Skip to content

Instantly share code, notes, and snippets.

@paoloambrosio
Last active December 19, 2015 12:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paoloambrosio/5952737 to your computer and use it in GitHub Desktop.
Save paoloambrosio/5952737 to your computer and use it in GitHub Desktop.
@mysetup
Feature: Complex setup feature
Scenario: Some scenario
Given some step
Scenario: Some other scenario
Given some step
package com.example.beforefeature;
import cucumber.api.Scenario;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
public class MySetupHook {
private static boolean uploaded = false;
private static boolean shotdownHookAdded = false;
@Before("@mysetup")
public void uploadIfNotUploaded() {
if (!uploaded) {
uploadFiles();
uploaded = true;
if (!shotdownHookAdded) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
deleteFilesIfUploaded();
}
});
shotdownHookAdded = true;
}
}
}
private static void uploadFiles() {
System.out.println("Uploading files"); // TODO
}
@Before("~@mysetup")
public void deleteFilesIfUploaded() {
if (uploaded) {
deleteFiles();
uploaded = false;
}
}
private static void deleteFiles() {
System.out.println("Cleaning up files"); // TODO
}
}
Feature: No setup feature
Scenario: Some scenario
Given some step
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment