Exclude rules from unit tests?

(KC Baltz) #1

I’m using SQ 7.3. In general, I agree with the No Magic Numbers rule (S109), but I’m not convinced it’s helpful in Unit Tests where literals are likely more readable than constants. Is there a way to disable a rule like this for a given source path (e.g. rule is enabled for src/main/java and disabled for src/test/java)?

I know we could use //SONAR for each one, but that’s potentially a lot of work.

See this discussion where the top two answers seem to agree:

(Adam Gabryś) #2

What it the configuration of your project? Do you execute SonarScanner for Maven or other version?

(KC Baltz) #3

I use Maven 3 to execute the scanner. Is there a good way to have different rules for the testSource? I don’t want to skip SQ entirely for unit tests I don’t think.

(Adam Gabryś) #4

It is impossible. I think this thread should be interesting for you: