Tutorial | Source | Issues | Release notes |
---|
class ExampleTest {
@Tested ServiceAbc tested;
@Injectable DependencyXyz mockXyz;
@Test
void doOperationAbc(@Mocked 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; }};
}
}
In a Maven pom.xml
file:
<dependency>
<groupId>org.jmockit</groupId> <artifactId>jmockit</artifactId> <version>1.xy</version>
<scope>test</scope>
</dependency>
In a build.gradle
file:
testImplementation 'org.jmockit:jmockit:1.xy'