Tests generated by Diffblue Cover

Test class location

The tests created by Diffblue Cover will be placed in a location within the project according to the following:

  1. If a test source directory (src/test/java) exists in the current project module, Diffblue Cover will add the tests there (project_root/module_for_MUT/src/test/java, where MUT = method-under-test).
  2. Otherwise, it will explore the modules in the project which depend on the module for which a test has been written. If any dependent module contains a test source directory, Diffblue Cover will put the generated test classes there (project_root/dependent_module/src/test/java).
  3. If no existing test source directory could be found in any dependent module, Diffblue Cover will generate a new test source directory in the same module as the class for which tests are generated (project_root/module_for_MUT/src/test/java).

Exception: The only exception to point 3 above is if the module is named in a fashion that suggests a different project hierarchy (e.g. the path to the MUT contains main), in which case the tests will be copied to project_root/src/test/java. In this situation it is possible that the created test classes will not compile, as the existing root module may not have a dependency on the module in which the MUT is located.

We recommend to always explicitly create a test source directory, in the relevant module or one of its dependent modules, so that Diffblue Cover knows where to put new test classes.

Insertion order

Generated test methods are inserted into a test class in the same order that the methods under test appear in the source class.

Source class:

public class MyClass {
  public void xyz() {
  public void abc() {

Test class:

public class GeneratedUnitTest {
  public void testXyz() {
  public void testAbc() {

As illustrated above, the test methods testAbc and testXyz are not inserted alphabetically into the test class, but instead according to how the methods under test are ordered. Test methods which test the same method are inserted in the order in which they are generated by Diffblue Cover.

Boilerplate tests

Normally, selecting Write Tests will generate one test per method. If the Diffblue Cover IntelliJ plugin is unable to create a usable test for a method, it will switch, by default, into "boilerplate" mode, where it will produce a template for a test based on values relevant to the source code under test. This will save test developers time over writing tests from scratch.

For example, the method in the following inner class in an outer class, DatabaseDao:

public static class Inner {
    private Inner(){};
    public void myMethod(Inner inner) {

could produce a boilerplate test like this:

  public void testInnerMyMethod() throws Exception {
    // Arrange
    String string = "This is a boilerplate test. Please fix.";
    DatabaseDao.Inner inner = null;
    DatabaseDao.Inner inner1 = null;

    // Act

Disabling the creation of boilerplate tests

In order to switch off this feature, uncheck the box for Generate boilerplate tests under Fallback Options on the Generation tab of the Diffblue Cover configuration screen, which can be found at Tools -> Diffblue Cover -> Generation -> Test Naming, under File -> Settings (Windows/Linux) or IntelliJ IDEA -> Preferences (macOS):

results matching ""

    No results matching ""