Getting started | About | Tutorial | Samples | API | Source | Issues | Community | History |
---|
See the Mocking Toolkit Comparison Matrix for more features.
public class ExampleTest {
@Tested ServiceAbc tested;
@Injectable DependencyXyz mockXyz;
@Test
public void doOperationAbc(@Mocked final AnotherDependency anyInstance) {
new Expectations() {{
anyInstance.doSomething(anyString); result = 123;
AnotherDependency.someStaticMethod(); result = new IOException();
}};
tested.doOperationAbc("some data");
new Verifications() {{ mockXyz.complexOperation(true, anyInt, null); times = 1; }};
}
}
Download jmockit-1.21.zip or use Maven:
<dependency>
<groupId>org.jmockit</groupId> <artifactId>jmockit</artifactId> <version>1.21</version>
<scope>test</scope>
</dependency>