Multiple issues on the same line unittests

Hello everyone,

I am developing a custom java plugin and during my tests I found out that sometimes I need to check that several issues are reported on the same line (in my case a method).

I have added the // Noncompliant {{message here}}
This works very well if there is only one issue reported on that line, but I need to test that 2 or more issues are reported on the same line.

Is this possible? I was going through documentation but without success.

I am using Sonar version 7.9.1, and sonar-java-plugin-

Any help will be appreciated,
Thanks in advance

Hello @marian31ian and welcome to this community.

I believe the javadoc in this file is what you are looking for. Note that this is the behavior of the current version, we reworked the CheckVerifier in version 8.3 of the Java analyzer. As far as I remember, it should be possible to do something similar in version 6.1 though.

Basically, you can use something like:

// Noncompliant@+2 [[sc=1;ec=7]] {{Highlight "public"}}
// Noncompliant@+1 [[sc=12;ec=15]] {{Highlight function name}}
public void fun(int arg) // Noncompliant [[sc=20;ec=23]] {{Highlight argument}}

Hope it helps.

1 Like

It works also in 6.1.
Thank you very much, this really helped me to solve the problem with my tests!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.