JMockit An automated testing toolkit for Java

Features

Example

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; }};
   }
}

Get JMockit

Download jmockit-1.29.zip or use your build tool.

In a Maven pom.xml file:

<dependency>
   <groupId>org.jmockit</groupId> <artifactId>jmockit</artifactId> <version>1.29</version>
   <scope>test</scope>
</dependency>

In a build.gradle file:

testCompile 'org.jmockit:jmockit:1.29'