0

I want to execute a block of code that changes based on a pass or a fail. Basically looking to set the results from a test in our test case tracking software. I created my own test rules, shown below, but no matter if the test passes or fails it always just calls succeeded.

public class TestRules extends TestWatcher {

@Override
public void succeeded(Description description){
    log.error("This should only be called when passing");
}

@Override
public void failed(Throwable e, Description description) {
    log.error("This Should only be called when Failing");
}

}

I set the rule in the test as follows

@Rule
public TestRules testRules = new TestRules()

I am hoping I am just missing something stupid and simple.

Mouse
  • 1
  • Hi Mouse, welcome to Stack Overflow! Do you get any error messages while executing this code? – StefanN Nov 21 '19 at 21:18
  • 1
    Yes, its possible via extensions of spock. The really good usage example has been given here, so you can create a listener that would be called by spock on error: https://stackoverflow.com/questions/25967241/does-spock-have-test-event-listeners – Mark Bramnik Nov 22 '19 at 14:17
  • @StefanN no errors, but no matter if the test fails or passes it just ignores the failed rule. – Mouse Nov 25 '19 at 19:14
  • @MarkBramnik Thanks, I have never used any of those but I will try to follow that as an outline and see if I can get it working. – Mouse Nov 25 '19 at 19:15

0 Answers0