FP on S2699: JUnit assertions not detected since update to Java plugin 3.13

234 views
Skip to first unread message

Vincent Privat

unread,
May 12, 2016, 7:16:23 PM5/12/16
to SonarQube
Hi,
Since we updated to latest Java plugin (3.13), S2699 triggers hundreds of false positives. It seems JUnit assertions are no longer detected.
We were using SQ 5.3 at the time of update (21st April, because we need web context) and now have updated to SQ 5.5 directly. The false positives are still here.

Here is an example of false positive:

package org.openstreetmap.josm;

import static org.junit.Assert.assertEquals;


import java.util.Collection;





import org.junit.Test;



/**
 * Unit tests of {@link Main} class.
 */
public class MainTest {
 
    /**
     * Unit test of {@link DownloadParamType#paramType} method.
     */
    @Test
    public void testParamType() {
Add at least one assertion to this test case.  
  •  
  • L23
  •  
  •  
  •  
  •  
  •  
  •  
  • 10min effort
  •  
        assertEquals(DownloadParamType.bounds, DownloadParamType.paramType("48.000,16.000,48.001,16.001"));
        assertEquals(DownloadParamType.fileName, DownloadParamType.paramType("data.osm"));
        assertEquals(DownloadParamType.fileUrl, DownloadParamType.paramType("file:///home/foo/data.osm"));
        assertEquals(DownloadParamType.fileUrl, DownloadParamType.paramType("file://C:\\Users\\foo\\data.osm"));
        assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("http://somewhere.com/data.osm"));
        assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("https://somewhere.com/data.osm"));
    }
 

I couldn't find any related ticket in JIRA nor a discussion about it on this forum.

Cheers,
Vincent


Michael Gumowski

unread,
May 13, 2016, 12:00:22 PM5/13/16
to Vincent Privat, SonarQube
Hello Vincent,

Thanks a lot for your feedback. Unfortunately I'm not able to reproduce the issue with version 3.13 (are you aware that bugfix version 3.13.1 have been released?).

Is your project a maven project, analyzed with the maven plugin?
If it's not, it could come from missing bytecode for tests (properties 'sonar.java.test.binaries' and 'sonar.java.test.libraries'), as it is automatically provided for maven project.

Could you provide a small test class with its class under test reproducing the issue?

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/ad8ce2d0-b0ec-4f16-a483-f4861b7ef46a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vincent Privat

unread,
May 13, 2016, 12:40:51 PM5/13/16
to SonarQube, vincent...@gmail.com
Hi Michael,
You're right, we're running Java plugin 3.13.1, not 3.13.
We're not using a Maven project. The project is analyzed through a custom Jenkins job, with integrated SonarQube Scanner (2.5.1).
The project is compiled with JDK7, then analyzed with JDK8.
I see SQ Scanner 2.6 is out, I will give it a try.

Concerning configuration: our setup works for more than a year, this problem occurs only since 21st April, and I didn't change anything. So it must come from a software update. The properties are set as follows:

sonar.java.binaries=build,test/build
sonar.java.test.libraries=test/lib/**/*.jar

The console output is attached. I see suspicious "INFO: Resource not found" statements, could it come from that?

Concerning a small test class, it won't help much. We got hundreds of errors, all our tests now suddenly trigger this error, and follow this pattern:

package org.openstreetmap.josm;

import static org.junit.Assert.assertEquals;

import org.junit.BeforeClass;
import org.junit.Test;
import org.openstreetmap.josm.Main.DownloadParamType;

/**
 * Unit tests of {@link Main} class.
 */
public class MainTest {

    /**
     * Setup test.
     */
    @BeforeClass
    public static void setUp() {
        JOSMFixture.createUnitTestFixture().init();
    }

    /**
     * Unit test of {@link DownloadParamType#paramType} method.
     */
    @Test
    public void testParamType() {
        assertEquals(DownloadParamType.bounds, DownloadParamType.paramType("48.000,16.000,48.001,16.001"));
    }
}

Best regards,
Vincent
console_sq.txt

Vincent Privat

unread,
May 16, 2016, 8:52:13 PM5/16/16
to SonarQube, vincent...@gmail.com
OK I see the plugin configuration has changed with the new property 'sonar.java.test.binaries'. My configuration still refers only to 'sonar.java.binaries', thanks for the hint and sorry for the noise.

Michael Gumowski

unread,
May 17, 2016, 2:56:16 AM5/17/16
to Vincent Privat, SonarQube
Okay, Thanks for letting us know!

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

On 17 May 2016 at 02:52, Vincent Privat <vincent...@gmail.com> wrote:
OK I see the plugin configuration has changed with the new property 'sonar.java.test.binaries'. My configuration still refers only to 'sonar.java.binaries', thanks for the hint and sorry for the noise.

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages