> For the complete documentation index, see [llms.txt](https://cover-docs.diffblue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cover-docs.diffblue.com/features/cover-annotations/test-organization-annotations.md).

# Test Organization Annotations

## 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.

```java
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.java
```

{% hint style="warning" %}
If an invalid classname is provided, Diffblue Cover will throw an error at environment checks stage.
{% endhint %}

{% hint style="info" %}
This annotation can only be applied at the class level.
{% endhint %}

### 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:**

```java
package com.example.myapp;

import com.diffblue.cover.annotations.WriteTestsTo;

// This class's existing test file has conflicts with merge mode
@WriteTestsTo("MyServiceDiffblueTest")
public class MyService {
    // Tests will be written to MyServiceDiffblueTest.java instead of MyServiceTest.java
}
```

{% hint style="info" %}
Use `dcover issues --prompt` to get AI-assistant-ready suggestions for which classes need `@WriteTestsTo` annotations.
{% endhint %}

See [Merge Mode](/features/cover-cli/writing-tests/merge-mode.md) for full documentation on merge mode and troubleshooting.
