When drilling down from the project dashboard, the component viewer is the ultimate place to view detailed information on a given file (or unit test file) on different axes.
Source Code File
When drilling down into measures, you will eventually reach the source code of a file and be able to browse its quality. SonarQube is shipped with 4 default perspectives (Coverage, Duplications, Issues, Source). Depending on the plugins that are installed, other perspectives may be available.
This perspective displays the source code with highlighted syntax as well as the main measures of the file.
To display the new/modified source code or view the last committers, you need to install the SCM Activity Plugin.
Since version 3.6, (on Java files only), usage and declaration of variables and methods are highlighted (limited to class scope). When clicking on a variable or on a method name, it is possible to see its declaration and usage.
- Where in the current file is this variable declared? Where is it used?
- Where in the current file is this method declared? Where is it used?
This perspective displays the source code decorated with information about code coverage (by unit tests and/or integration tests).
In the source code:
- The first column displays the number of unit tests covering the line (available since version 3.5 for Java - requires a specific configuration to mapping unit tests and covered code, was the number of hits by unit tests in versions prior to 3.5)
- The second one displays the number of covered conditions by unit tests out of the total number of conditions to cover
When clicking on a figure displayed in the first column, the unit tests covering this specific line are listed:
When selecting Per test > Covered lines in the second dropdown list, a third dropdown list appears. In this latter list, it is possible to select a specific unit test. Then, only lines covered by this unit test are displayed:
This perspective displays issues directly in the source code.
The issues to display can be filtered by coding rule, severity, etc.
Thanks to the Time changes... list box, you can limit the display to issues that were added in the selected time span. See Differential Views for more information.
A few lines of context are provided around each issue. If necessary, you can display the full source code by ticking the Full source box.
You can directly manage the issues: comment, assign, link to an action plan, etc. See the Issues documentation page for more details.
This perspective displays every duplicated chunk of code. See Duplications for more information.
Unit Test File
When drilling down into unit tests execution measures, you will eventually reach the unit test level.
This perspective displays the source code of the unit test file.
This perspective displays the result of the unit tests belonging to the unit test class. In case of a failure or an error, the reason is displayed:
It is also possible to see the mapping of unit tests and covered code. The objective is to answer the following questions:
- Which files are covered by a given unit test?
- How many lines of code are covered by a given unit test?
- Which lines are covered by a given unit test?
- Which tests cover a given line of code?
This perspective displays issues on unit tests: