Diffblue Cover’s IntelliJ plugin analyzes any class or method in your Java application and automatically writes unit tests, saving you from having to spend hours manually writing tests throughout your development process.

Download Free Plugin

Given the importance of testing, we want to make sure that every developer has access to automating the mundane and complex task of writing unit tests. As a result, we’ve updated our End-User License Agreement to allow every developer to use Diffblue Cover: Community Edition for both open-source and commercial Java code, free of charge.

Every test created by Diffblue is easy to read and understand for any developer, as if they were written by a colleague.

Here is the source code:

@Service
public class CloudStorageService {

  @Autowired
  private AmazonS3 amazonS3;

  public PutObjectResult uploadFileToBucket(String bucketName, String key, File file) {
    try {
      return amazonS3.putObject(bucketName, key, file);
    } catch (AmazonS3Exception e) {
      throw new IllegalStateException("Totally handled this exception", e);
    }
  }
}

Here is the code produced by Diffblue Cover:

@ContextConfiguration(classes = {AmazonS3.class, CloudStorageService.class})
@ExtendWith(SpringExtension.class)
public class CloudStorageServiceDiffblueTest {
  @MockBean
  private AmazonS3 amazonS3;

  @Autowired
  private CloudStorageService cloudStorageService;
  @Test
  public void testUploadFileToBucket() throws SdkClientException {
    // Arrange
    PutObjectResult putObjectResult = new PutObjectResult();
    when(this.amazonS3.putObject(anyString(), anyString(), (File) any())).thenReturn(putObjectResult);

    // Act and Assert
    assertSame(putObjectResult, this.cloudStorageService.uploadFileToBucket(
      "bucket-name", "Object-key", Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toFile()));
    verify(this.amazonS3).putObject(anyString(), anyString(), (File) any());
  }
}

Writing unit tests using Diffblue Cover: Community Edition

You can download our IntelliJ plugin from our website or by searching for Diffblue Cover in the JetBrains marketplace.

Download Free Plugin

Once installed, Diffblue Cover will index your project. This may take several minutes to complete depending on the size of your Java application. After this is complete you just need to right-click on any class or method within your application and select “Write Test.”

The tests will be available for you to review under src/test/java.

Testing is an ongoing process to ensure that you are not injecting failure into your code. After you’ve written tests for your project, you should rerun Diffblue Cover every time to make changes to your codebase. This will keep everything running smoothly, give you confidence when you commit changes, and help uncover regressions you’ve introduced before your colleagues or customers are impacted.

Is Diffblue Cover: Community Edition really free?

Diffblue Cover: Community Edition is completely free and doesn’t require any payment for creating tests for individual users.

Download Free Plugin

There are two premium options available if you want more access to premium features or support:

Diffblue Cover: Individual Edition

A paid version of our IntelliJ plugin for individual users. You can upgrade to Diffblue Cover: Individual Edition in the JetBrains Marketplace.

Diffblue Cover: Teams Edition

A product designed for teams and enterprises, the Teams Edition of Diffblue Cover offers a CLI tool and a more powerful feature set. The CLI tool runs, updates, and manages your unit tests in the background, so you don’t have to manually run tests for each class or method. It keeps your entire team’s unit testing in sync with each other and provides you access to additional tools to measure and monitor your code coverage. You can sign up for a free trial here.