Problem in testing exception-throwing spock extensions #656

Open
Vampire opened this Issue Oct 3, 2016 · 2 comments

Projects

None yet

2 participants

@Vampire
Contributor
Vampire commented Oct 3, 2016

I'm trying to write some Spock tests for JMockit (to test Groovy / Spock support I'm working on) and stumbled over the problem that there is no good way to verify a thrown exception by some interceptor. JMockit will validate in a feature method interceptor some expectations and throw an exception if they are not satisfied.

As this happens right after the feature method, using thrown() does not work, as it happens too soon.

Using a JUnit ExpectedException rule does not work either, as the BaseSpecRunner catches and somehow handles the exception, so that you cannot catch it in a JUnit rule.

This same problem exists for any Spock extensions that should be tested with spock and that does some checks in a feature method interceptor and eventually throws an exception.

@Vampire
Contributor
Vampire commented Oct 27, 2016 edited

I just found @FailsWith, but that also does not work, as the JMockit interceptor that throws the exception seems to wrap the FailsWithInterceptor and so the FailsWithInterceptor complains that no exception was thrown.

@pniederw
Contributor

Try org.spockframework.EmbeddedSpecification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment