# SonarQube Warnings

There are various SonarQube warnings that may be issues for tests created by Diffblue Cover. This page lists common warnings and how to address them, if they can be addressed. Note that there are specific ways to address SonarQube warnings in the [Diffblue Cover Plugin](/features/cover-plugin/cover-plugin-admin/using-sonarqube-with-cover-plugin.md) and [Diffblue Cover CLI](/features/cover-cli/cover-cli-admin/using-sonarqube-with-cover-cli.md). This page is for an overview of the warnings you may see and how they can be addressed with any version of Diffblue Cover.

## Configurable Warnings

### Refactor this method to reduce the number of assertions from X to less than N

CLI only: Use the `--max-assertions-per-test=(N-1)` option to limit the number of assertions per test.

### Add at least one assertion to this test

There are two common causes for this warning.

1. An option has been given to Diffblue Cover to keep partial tests (docs for [plugin](/features/cover-plugin/writing-tests/partial-tests.md) or [CLI](/features/cover-cli/writing-tests/partial-tests.md)) or [skeleton tests](/features/cover-plugin/writing-tests/skeleton-tests.md). In this case, tests without assertions are expected and the tests should be completed manually.
2. This is due to SonarQube failing to recognize certain assertion methods. Most likely, you have to do the following:

   Add `org.springframework.test.web.servlet.ResultActions#andExpect` to the `customAssertionMethods` parameter for rule `S2699`. This explicitly tells SonarQube to treat `andExpect` as an assertion.

### Test method naming conventions

By default, Diffblue Cover’s test method naming complies with the pattern `[a-z][a-zA-Z0-9_]*` You can change the method naming template if you want to create test names without underscores, for example. See method name template for [plugin](/features/cover-plugin/cover-plugin-settings/test-naming.md#method-name-template) or [CLI](/features/cover-cli/writing-tests/test-naming.md#method-name-template).

## Unresolvable Warnings

Note that these warnings are where SonarQube and Diffblue Cover have different beliefs about what is best. These cannot be easily adjusted in Diffblue Cover, so the best approach is to suppress these or use other approaches as described for the [Diffblue Cover Plugin](/features/cover-plugin/cover-plugin-admin/using-sonarqube-with-cover-plugin.md) and [Diffblue Cover CLI](/features/cover-cli/cover-cli-admin/using-sonarqube-with-cover-cli.md).

### Change the assertion arguments to not compare dissimilar types

SonarQube may incorrectly flag this situation when testing that the `equals` method of a class returns `false` when called with differing types.

### Swap these two arguments so they are in correct order: expected value, actual value

This is not expected to happen. If you see this file a support request with a concrete example of test code generated by Cover.

### Replace these N tests with a parameterized test

Diffblue Cover currently does not support parameterized tests. This feature is on the roadmap. Stay tuned.

### Long variables

Diffblue Cover prefers long, descriptive variable names which may have up to about 40 characters.

### Local variable could be final

Local variables in tests generated by Diffblue Cover are never reassigned by construction. Diffblue Cover does not mark them using the `final` keyword.

### Unit test assertions should include message

Diffblue Cover does not generate such messages as they unnecessarily increase the verbosity and thus reduce the readability of the tests.

### Comment required for field

Diffblue Cover does not add JavaDoc comments to field declarations in test classes as they unnecessarily increase the verbosity and thus reduce the readability of the tests.


---

# 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/get-started/diffblue-learning/sonarqube-warnings.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.
