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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cover-docs-preview.diffblue.com/features/cover-annotations/test-organization-annotations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
