Test Tagging

Diffblue Cover will automatically annotate tests and support methods created. This allows Cover to accurately measure coverage and to provide maintenance capabilities.

Tests Managed By Diffblue

Diffblue Cover identifies and manages generated tests by either: specific tags or the class the tests belong to. The exact conditions are listed below:

  • The tests are tagged with @ManagedByDiffblue annotations (introduced in Cover annotations 1.4.0).

  • The tests are tagged with @Tag("MaintainedByDiffblue") annotations (from Cover annotations 1.3.0).

  • The tests are untagged, but reside within DiffblueTest Classes (whose naming convention can be configured; see class-name-template).

Note: Support for @Tag("MaintainedByDiffblue") is deprecated, and will be dropped in a future release. We recommend updating to the latest version of Cover Annotations to ensure continued support for your Diffblue Tests. See Cover Annotations.

This designation means that Diffblue Cover can overwrite, modify, or remove these tests. For example, you can maintain Diffblue tests using commands like dcover remove, dcover clean, or dcover validate. These tests can also be overwritten and changed in future uses of dcover create if their associated method is modified.

Here's an example of a tagged Diffblue Test:

  @Test
  @ManagedByDiffblue
  @Tag("ContributionFromDiffblue")
  void testAdd_whenOne_thenReturnThree() {
    // Arrange, Act and Assert
    assertEquals(3, new Calculator().add(1, 2));
  }

Tests that Contribute to Diffblue Coverage

Tests that Diffblue Cover has helped create (i.e. tests that have had a contribution from Diffblue Cover) will be included in the measurement of Diffblue Coverage if they are either:

  • Tagged with an @Tag("ContributionFromDiffblue") annotation.

  • Tagged with an @Tag("MaintainedByDiffblue") annotation (which also served this purpose).

  • Untagged, but reside within a DiffblueTest class.

This ensures that the coverage generated by these specific tests is accurately categorized as "Diffblue Coverage" in your reports.

How Test Tags are Applied and Managed

Test tagging annotations are automatically added by Diffblue Cover when tests are generated; there is no need to manually apply or adjust these annotations.

When a test is edited and should no longer be considered a Diffblue test, consider removing the @ManagedByDiffblueannotation. This ensures that the manual changes are preserved and not overwritten during future uses of dcover create.

The tags @Tag("ContributionFromDiffblue") or @Tag("MaintainedByDiffblue) should not be removed or adjusted, doing so will lead to an invalidation of Diffblue test coverage output. .

Last updated

Was this helpful?