Sign in Agent Mode
Categories
Your Saved List Become a Channel Partner Sell in AWS Marketplace Amazon Web Services Home Help

Generating Java Unit Tests on Autopilot

  • By Philip R.
  • on 06/17/2024

What do you like best about the product?
As an IT consultant with a fokus on Spring Boot and testing, I am always on the lookout for tools that can enhance my productivity and make automated testing more easy to tackle for team.

Recently, I had the opportunity to integrate Diffblue Cover into my workflow for one project.

Here's what I liked most about Diffblue Cover:

Automatically Generate Tests for Legacy Projects

For brownfield and legacy projects that have little to no test coverage, Diffblue Cover quickly helps to provide a base test coverage for the project. Writing hundred of tests manually for classes you've never seen before is a cumbersome and time-consuming process. With the help of Diffblue Cover, I could easily generate a test-baseline while executing a single command. This is a great benefit to avoid regressions due to untested code.

Simple Test Skeleton Generation

Another major advantage of Diffblue is its capability to generate test skeletons. As Diffblue Cover analyzes the matching production code, it will generate tests for corner cases and all exeuction paths (if-else branches). These tests come with the relevant setup and test data to verify the class under test.

Increased Productivity

Diffblue Cover comes with both an IntelliJ IDEA integration as well as a CLI tool. The IDE integration helped me during daily development to trigger Diffblue's reinforcement learning model to analyze the code and write tests. The integration in the IDE is easy to install and user-friendly. You generate tests with a click on the method you want test for.

For larger codebases and to automate the test generation process, the CLI tool helps to include Diffblue Cover into a pipeline or CI/CD workflow.
What do you dislike about the product?
While my overall experience with Diffblue Cover is positive, there are a few areas where the tool could improve its functionality.

Test Method Naming

One of the areas where Diffblue can improve is in the generation of test method names. The generated names, while functional, often lack the clarity and descriptiveness for test cases.

Clear and descriptive method names are important for maintaining readable and maintainable code. When Diffblue Cover creates mutliple tests for a single method, it uses counter in the test method name to differentiate the tests. A better approach could be to include the actual test corner case in the method name.

Going Beyond Unit Tests

As Diffblue Cover focusses on the unit testing part of Java applications, developers can't fully use the tool on auto-pilot for a covering test suite.

While Spring Boot and Spring Test offer excellent support for sliced testing and integration testing, developers have to consider when a unit test is sufficient and when to write a broader integration test.

The potential danger lies in neclacting integration tests when focussing only on the unit testing part. While this is not an issue of Diffblue Cover per se, developers might be tempted to write less integration test. This highly depends on the context of the class under test.
What problems is the product solving and how is that benefiting you?
Write Java unit tests on scale, help generate test skeletons, generate a test baseline for untested and legacy Java code