views:

145

answers:

0

I found jmockit a great mocking framework and jbehave a great way doing software testing. However, I'm unable to coordinate the two.

In order to run jbehave in eclipse, I create a class that extends the JUnitScenario. This class in turn use a Steps class. And I place several mocks inside this Steps class. However, when being executed, JMockit is not happy with this setting, so it throw exception:

java.lang.IllegalStateException: No mocked types in scope; please declare mock fields or parameters for the types you need mocked
    at mockit.internal.expectations.RecordAndReplayExecution.validateThereIsAtLeastOneMockedTypeInScope(RecordAndReplayExecution.java:157)
    at mockit.internal.expectations.RecordAndReplayExecution.<init>(RecordAndReplayExecution.java:75)
    at mockit.internal.state.ExecutingTest.setUpNewRecordAndReplay(ExecutingTest.java:60)
    at mockit.internal.state.ExecutingTest.getRecordAndReplayForVerifications(ExecutingTest.java:98)
    at mockit.Verifications.<init>(Verifications.java:110)
    at mockit.Verifications.<init>(Verifications.java:86)
    at mockit.FullVerifications.<init>(FullVerifications.java:51)

Looks like JMockit sees the Scenario class as the context of the test so that it won't see any mocked types I declared inside the Steps class.

Is there any possible way to change it and make JMockit seeing the context correctly?

Here is the maven project that can be use to reproduce the problem: http://seamoo.com/jmockit-jbehave.tar.gz