IntelliJ - Analysis on test sources

1,455 views
Skip to first unread message

alexis...@gmail.com

unread,
Dec 5, 2016, 9:27:30 AM12/5/16
to SonarLint
Hi team,

First, I'd like to thank you much for your work :)

We are using IntelliJ IDEA Community Edition 2016.3 with SonarLint plugin 2.4.3.1360 as well as SonarLint for Command Line 2.0 both in connected mode to same SonarQube 5.6.3 instance.
Issue is Command Line version is set-up to analyze test sources (src/test/java) while I can't find a way to have IntelliJ analyze them.
-> Any hints ?

Thanks in advance !

Duarte Meneses

unread,
Dec 5, 2016, 9:41:57 AM12/5/16
to Alexis LEGROS, SonarLint
Hello,

SonarLint for IntelliJ should also analyze test sources by default. Some rules don't apply to test sources.
Could you check the SonarLint console (in the SonarLint tool window) to see what happens?

If debug is enabled, you should see something like this:

Analysing 'SonarLintTestUtils.java'...
Starting analysis with configuration:
[
  moduleKey: org.sonarqube:cpp-simple-sq-scanner
  baseDir: /git/sonarlint-intellij
  workDir: /git/sonarlint-intellij/.idea/sonarlint
  extraProperties: {sonar.java.target=1.8, sonar.java.source=8, sonar.java.libraries=......}
  inputFiles: [
    /git/sonarlint-intellij/src/test/java/org/sonarlint/intellij/SonarLintTestUtils.java [test]
  ]
]


Note the "[test]" after the file name, which means that the file is being qualified as a test file and some rules won't apply to it.

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/1eb504aa-ffb2-441f-98c1-3fa3c22a2f93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Duarte MENESES | SonarSource

Julien HENRY

unread,
Dec 5, 2016, 9:43:44 AM12/5/16
to Alexis LEGROS, SonarLint
Hi Alexis,

Thanks for your kind words, that's appreciated.

2016-12-05 15:27 GMT+01:00 <alexis...@gmail.com>:
Issue is Command Line version is set-up to analyze test sources (src/test/java) while I can't find a way to have IntelliJ analyze them.
-> Any hints ?

By default SonarLint for CLI will analyze all files since it has no way to guess what are main/test code. That's up to you to pass correct arguments: --src=src/main/** --tests=src/test/**

Most of our rules are intentionally not raising issues on test files, since we consider that this is not the same level of expectation. That's why you may think test files are not analyzed in IntelliJ.

++

Julien

alexis...@gmail.com

unread,
Dec 7, 2016, 4:38:07 AM12/7/16
to SonarLint, alexis...@gmail.com
Hi guys,

Thanks a lot for your quick answers.

I got your point but detected a potentially unexpected behavior while trying to set better parameters to SonarLint for Command Line execution, thanks to your advice, Julien.
It seems the program won't take account of --tests if its path is not included in --src param value.

1st call : src does not include tests, test classes aren't detected
>cmd.exe /c ..\sonarlint-cli-2.0\bin\sonarlint.bat --src **/src/main/** --tests **/src/test/** --exclude **.jasper

INFO: Java 1.8.0_05 Oracle Corporation (64-bit)
INFO: Windows 7 6.1 amd64
INFO: Connected mode (20161007)
INFO: Using storage for server 'PIC v2' (last update 30/11/16 11:12)
INFO: Index files
INFO: 190 files indexed
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
INFO: Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property
INFO: JavaClasspath initialization (done) | time=4ms
INFO: JavaTestClasspath initialization
INFO: Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property
INFO: JavaTestClasspath initialization (done) | time=1ms
INFO: Java Main Files AST scan
INFO: 53 source files to be analyzed
INFO: Java Main Files AST scan (done) | time=3825ms
INFO: 53/53 source files have been analyzed
INFO: Java Test Files AST scan
INFO: 0 source files to be analyzed
INFO: Java Test Files AST scan (done) | time=0ms
INFO: 0/0 source files have been analyzed
INFO: 2 source files to be analyzed
INFO: Unit Test Coverage Sensor is started
INFO: 2/2 source files have been analyzed
INFO: Integration Test Coverage Sensor is started
INFO: Overall Coverage Sensor is started
INFO: 55 source files to be analyzed
INFO: 55/55 source files have been analyzed
INFO:

-------------  SonarLint Report  -------------

          85 issues (190 files analyzed)

          17 major
          66 minor
          2 info

-------------------------------------------

INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 6.979s
INFO: Final Memory: 4M/96M
INFO: ------------------------------------------------------------------------

2nd call, src includes tests, they get analyzed.
>cmd.exe /c ..\sonarlint-cli-2.0\bin\sonarlint.bat --src **/src/** --tests **/src/test/** --exclude **.jasper

INFO: Java 1.8.0_05 Oracle Corporation (64-bit)
INFO: Windows 7 6.1 amd64
INFO: Connected mode (20161007)
INFO: Using storage for server 'PIC v2' (last update 30/11/16 11:12)
INFO: Index files
INFO: 200 files indexed
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
INFO: Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property
INFO: JavaClasspath initialization (done) | time=0ms
INFO: JavaTestClasspath initialization
INFO: Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property
INFO: JavaTestClasspath initialization (done) | time=0ms
INFO: Java Main Files AST scan
INFO: 53 source files to be analyzed
INFO: Java Main Files AST scan (done) | time=4118ms
INFO: 53/53 source files have been analyzed
INFO: Java Test Files AST scan
INFO: 10 source files to be analyzed
INFO: Java Test Files AST scan (done) | time=297ms
INFO: 10/10 source files have been analyzed
INFO: 2 source files to be analyzed
INFO: Unit Test Coverage Sensor is started
INFO: 2/2 source files have been analyzed
INFO: Integration Test Coverage Sensor is started
INFO: Overall Coverage Sensor is started
INFO: 55 source files to be analyzed
INFO: 55/55 source files have been analyzed
INFO:

-------------  SonarLint Report  -------------

          85 issues (200 files analyzed)

          17 major
          66 minor
          2 info

-------------------------------------------


INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 7.582s
INFO: Final Memory: 4M/98M
INFO: ------------------------------------------------------------------------

Best regards,
Alexis.

Julien HENRY

unread,
Dec 7, 2016, 4:44:09 AM12/7/16
to Alexis LEGROS, SonarLint
Oups, my bad. We are following a different approach than in SonarQube scanner so I got confused. Here is the SonarLint way:
  - --src is to specify entire source set (may be test or not). Default is to include everything.
  - --tests is to precise what are test files inside the source set

So you second run is exactly what is intended:

sonarlint.bat --src src/** --tests src/test/**

++

Julien

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