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 can use the "boilerplate" mode, if enabled (see below), 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:

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

    // Act
    inner.myMethod(inner1);
  }

Enabling the creation of boilerplate tests

In order to switch this feature on, under File -> Settings (Windows/Linux) or IntelliJ IDEA -> Preferences (macOS), select Tools -> Diffblue Cover, then select the Generation tab of the Diffblue Cover configuration screen, and in the Fallback Options section, check the box for Generate boilerplate tests.

results matching ""

    No results matching ""