Is it possible to use a second quality gate in the same project for my test folder?

Background: Our developers have more duplicated code in their tests than in the actual code. So basically, we want to try to allow them 10% duplicated lines in all files of the test folder and only 3% in all other files.

Any way to achieve this or does anybody have an alternate solution for this?


Hey there.

For the most part, SonarCloud is designed to analyze source code rather than test code – with a few exceptions (we’ve dipped our toes into writing more rules specifically for test code in the last few years). When sonar.sources and sonar.tests are configured correctly, you’ll find that very few rules are actually supposed to apply to test code.

Quality Gates are really not built for test code for the reason you’ve mentioned – different rules/standards apply to this kind of code.

It’s imperfect – why wouldn’t you want to hold your test code to high standards? And it’s something we haven’t found the perfect solution for yet. It’s on our radar. For now, if you really wanted to accomplish something like this, you’d need to have two separate projects (possibly configured as a monorepo) – one analyzing your “real” source code, and the other analyzing your test code as source code.

Hey @Colin
thank you very much for your answer :raised_hands: I guess we will take a look into separating the tests or just excluding them from the quality scan.