Test Organization Annotations
Test organization annotations allow users to control how tests are organized and structured.
Using @WriteTestsTo
The @WriteTestsTo annotation is available from cover-annotations version 1.9.0.
The @WriteTestsTo annotation directs Diffblue Cover to write tests for a specific source class into a designated test class file, rather than following the default naming template (configured via --class-name-template).
Basic Usage
The specified test class name must be a valid Java classname, and the test class will be created (if it does not already exist) in the test folder under the same package structure as the source class.
package com.example.myapp;
import com.diffblue.cover.annotations.WriteTestsTo;
@WriteTestsTo("CustomTestClassName")
public class SourceClass {
public String getValue() {
return "example";
}
}
// Tests will be written to: src/test/java/com/example/myapp/CustomTestClassName.javaIf an invalid classname is provided, Diffblue Cover will throw an error at environment checks stage.
Using @WriteTestsTo as an Escape Hatch for Merge Failures
When using merge mode (--merge), Diffblue Cover attempts to merge generated tests into existing test classes. If the merge fails (indicated by output code R090), you can use @WriteTestsTo to direct tests for that specific class to a separate file.
Example - Resolving R090:
See Merge Mode for full documentation on merge mode and troubleshooting.
Last updated
Was this helpful?

