Skip to main content

Disable Code Duplication smells in tests

I feel fine with having a bit more code duplication in my tests than in other code. But I can’t seem to disable the warnings. I’ve tried both with comments and a config file.

My code is C#. I’ve added the hint as this:

```cs
[Fact] // @codescene(disable:"Code Duplication") public async Task CloseAccount_Should_FailOnWrongPassword() {
}
```

But the method is still marked as Code Duplication.

I’ve also created a .codescene/code-health-rules.json that looks like this:

```json
{ "usage": "Code Health", "rule_sets": [ { "matching_content_path": "Carehood.Api.IntegrationTests/**", "rules": [ { "name": "Code Duplication", "weight": 0.0 } ] } ] }
```

I still see the warning in both VS Code and Rider.

Status: Answered3 comments

Log in to comment and vote

Comments3

  • Brown Oak

    •

    Oct 8, 2025

    I have cs methods with attributes and disabled code smells, and all works fine, smells are being ignored by CodeScene. The only difference between your example and my code is that I have disablement comment above attributes, like this:
    ```cs
    // @codescene(disable:"Code Duplication")
    [Fact]

    public async Task CloseAccount_Should_FailOnWrongPassword() {
    }
    ```

    I guess CodeScene is considering attributes part of the method, which is probably valid reasoning…

    P.S. I am using VSC, and I don’t have rules file at all.

    • Moccasin Sheep

      •

      Oct 8, 2025

      Yes! You’re absolutely right! Having the command above the attributes worked!

  • Beige Kangaroo

    •

    Oct 7, 2025

    In the JSON file, the pattern in matching_content_path will match from the repository root. (The reason being that CodeScene supports projects with multiple repositories). So, unless Carehood is the name of the repo, your pattern should be **/Carehood.Api.IntegrationTests/**