Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info
iconfalse
titleTable of Contents

Table of Contents
maxLevel2

 

When drilling down from the project dashboard, the resource viewer is the ultimate place to view detailed information on a given resource: file or unit tests file. The power of the tool comes from the fact that the resources can be viewed according to different axes of quality.

Viewing Source Code

When drilling down into measures, you will eventually reach the file level and will be able to browse the source code.

Image Removed

Sonar is shipped with 6 default tabs. Depending on the plugins you have installed, other tabs may be displayed.

Source Tab

This tab displays source code with highlighted syntax.

Image Removed

To display the new/modified source code or view the last committers, you need to install the SCM Activity Plugin.

Coverage Tab

The Coverage tab displays the source code decorated with information about code coverage (by unit tests and/or integration tests).

Image Removed

In the source code:

  • The first column displays the number of unit tests covering the line (available since Sonar 3.5, 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

Image Removed
The features described below are available since Sonar 3.5.

When clicking on a figure displayed in the first column, the unit tests covering this specific line are listed:

Image Removed

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 in the source code viewer:

...

Violations Tab

The Violations tab displays violations with their related reviews directly in the source code.

Image Removed

The violations to display can be filtered by coding rule, severity, etc.

Thanks to the Time changes... list box, you can only display new violations that have been added for a timespan. See Differential Views for more information.

Only the source code around the violations is displayed. If necessary for investigation purpose, you can display the full source code by ticking the Full source box.

...

Duplications Tab

...

See Duplications for more information.

Dependencies Tab

...

LCOM4 Tab

...

Viewing Unit Tests File

When drilling down into unit tests execution measures, you will eventually reach the unit test class level:

Image Removed

Source Tab

This tab simply displays the source code of your unit test class:

Image Removed

Tests Tab

This tab displays the result of the unit tests belonging to the unit tests class.

In case the test failed or was in error, the reason of the issue can be viewed.

Image Removed

Violations Tab

This tab displays the violations on the unit tests:

Image Removed

In greater detail

Children Display
alltrue

 

The component viewer is the heart of SonarQube: it displays the source code of a file (both source and test files), and all relevant information about it:

  • Overall file measures, like lines of code, complexity, number of methods, ...etc
  • Issues (generated by the rules activated on the quality profile)  and their related technical debt
  • Duplicated blocks within the same file or in other files, from both within the project and in other projects (if cross-project duplication is activated).
  • Lines and branches covered by unit or integration tests
  • SCM information (if the SCM Activity Plugin is installed) like who last committed a specific line and when
  • All tests of a given test file, along with their execution time and their status

 

You will land on the component viewer:

  • when drilling down from project dashboards using hunting services.
  • when reviewing issues on the Issues page or in the Issues Drilldown.
  • when searching for a particular file using the search input at the top-right.

General overview

Layout

The component viewer is composed of 3 parts:

  • The header lies across the top of the file. It displays useful information and offers decoration and filtering actions.
  • The workspace sits along the left of the file, and is used to keep track of navigation between files.
  • The source code is in the center, decorated with additional information based on the options chosen in the header.

Image Added

Header

The header can contain up to 5 tabs, one per main axis: Overall Measures, Technical Debt and Issues, Coverage (for source files) or Tests (for test files), Duplications, and SCM. Tabs which aren't relevant to the current file won't be shown. For instance, if the project has no tests, the coverage tab will be omitted. Similarly, the duplications tab will be omitted if there are no duplications, and the SCM tab will be missing if the relevant plugin is not installed.

You can click on each tab to show its detailed metrics in a row below the tabs. Click the same tab again to toggle display of the metrics row.

Each tab consists of two parts: a thin blue line at the top, which controls decoration, and the tab itself, which controls filtering.

Info
titleExpanding a tab does not activate a filter nor toggle decoration

Clicking on a tab does not have any impact on the source code that is displayed. It just shows detailed information about the code. You have to explicitly click on a filter or on a decoration bar to change something on the source code.

Decoration

On top of each tab (except the first one), a light blue bar can be toggled to activate decoration of the source code with information relevant to the tab. 

  • The decoration action modifies which information is visible on the source code. For instance, you can click the thin blue bar at the top of the SCM tab to show the file's SCM annotations. 
  • Multiple decorators can be turned on at the same time.
  • Once a decorator is activated (the light blue bar becomes darker) you may need to scroll down to find an instance of the relevant decoration. For instance, if you turn on the duplications decoration, the file you're looking at may not have a duplicated block at the top part of the file; you may need to scroll down to find one.

Filtering

When a tab is expanded, it gives access to filtering actions:

  • Filtering actions modify which part of the source code is visible
  • They can be toggled by clicking any metric in the tab that has ">" next to it. For instance, in the issues & technical debt tab, you can click on info > to show only code with info-level issues (and a few lines of context around those issues.)

 

Info
titleOnly one filter can be applied at a time across all the tabs

This means that if you activated the "Unresolved issues" filter in the Issues tab and you expand the Coverage tab, nothing will change in the source code until you select one of the filters of the Coverage tab.

 

Decoration and filtering work independently of each other. For instance, it's possible to filter the source code to see only the parts where there are info issues, while keeping the coverage information displayed on those lines - like in the example below:

Image Added

If you click on one of the filters available on the Issue, Coverage, or Duplication tabs, the component viewer automatically toggles the appropriate decoration for you if it's not already active.

The Workspace

The workspace keeps track of your navigation history when you use the features of the component viewer itself to navigate between files. It can help you:

  • remember which files you've just visited 
  • quickly move back to one of them

Image Added

It is populated as soon as you initiate navigation using either Duplicationed blocks, or Coverage per tests

Note that the workspace is automatically cleaned up once you stop navigating through these 2 features.

The source code

The main purpose of the component viewer is to show source code:

Image Added

Info
titleHighlight of usage and declaration of variables and methods is available for Java only

This feature is available for Java code only for the moment, and limited to the scope of the file. It allows you to answer the questions:

  • Where is this variable or method declared? 
  • Where is it used?

Eventually, this feature should be available for other languages and for identifiers declared outside the current file.

More

To learn more about the decorating and filtering capabilities of each of the header tabs, please see