Last active
December 19, 2015 12:09
-
-
Save paoloambrosio/5952737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mysetup | |
Feature: Complex setup feature | |
Scenario: Some scenario | |
Given some step | |
Scenario: Some other scenario | |
Given some step |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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