I am looking for a way to trigger a specific method in my JUnit class before and after a specific scenario. I see that it is possible to call a function, but is there any way to 'bind' them with the associated Java class?
Example Java test class:
@Runwith(Karate.class)
public class MyTest {
public void runThisBeforeScenarioOne() {
// Run this before scenario one
}
public void runThisAfterScenarioOne() {
// Run this after scenario one
}
public void runThisBeforeScenarioTwo() {
// Run this before scenario two
}
public void runThisAfterScenarioTwo() {
// Run this after scenario two
}
}
Feature file:
Feature: my test
Background:
* url 'http://myurl.com'
Scenario: one
Given request {"example": "example"}
When method post
Then status 200
And match response == {"result":"example"}
Scenario: two
Given request {"example": "example"}
When method post
Then status 200
And match response == {"result":"example"}