Test the Sonar-runner of sonarqube Automation test

Source: Internet
Author: User

On the Internet to read a lot of Sonarqube tutorials, first of all to explain the relationship between the two Sonarqube is a(Code Quality Management platform) Open source platform, used to manage the quality of Java source code, popular point of view that the person is actually similar to a server, like Tomcat or JBoss. With the server this empty shelf must not be detected code, And Sonar-runner is equivalent to a scanning code under the platform of the tool, both with the use to perform general automated testing (suitable for any project use, MAVEN engineering and Ant Engineering also apply) there are several other situations, in the future slowly stated, began to get to the point, That is, how to test.

Here are some suggestions: no matter what the problem, we from this is what, why, how to cut into the problem, the angle of looking at things will deepen a layer.

To test the environment Win7 32/64

Readiness: JDK environment, more than 1.5 versions, existing databases (oracle,mysql,sqlserver, etc.)

Test:

Step 1: Install Sonarqube

First unzip the sonarqube to any directory (the directory does not have Chinese)

eg

Here I use 5.1.1 version, the link address of this version is: http://www.sonarqube.org/downloads/,

This website has been updated to the 5.1.2 version,

Sonarqube is not required to configure the environment variable, only need to extract it to the specified directory, and is free of installation, directly can be used, the root directory of the bin directory entered after the appropriate operating system and the number of digits, After entering, click Startsonar.bat to run the service. It must be installed before running the JDK, if the failure to start the service, the command line appears wrapper stopped, then restart the computer, the general will be resolved , After startup, enter localhost:9000 (the default port number for Sonarqube) on the server and click Login, the default account name and password are admin and admin. Enter if this page appears, the Sonarqube platform starts successfully. (Here the small part has replaced the original English into Chinese, we first entered the Chinese, OH), Chinese need to download plug-ins in the official website to install or online installation.

The way to install online is:

Settings (config)-update Center (Upgrade center)-available Plugins (available plugins)-localization (localized)-Select Chinese Pack, click on the Install button, After restarting Sonarqube, it is Chinese.

After entering the configuration Sonarqube configuration, the configuration file in the Sonarqube installation directory under the Conf directory, enter after click Sonar.properties, for editing

Fill in four values here, respectively

Sonar.jdbc.username=root//Database user connection Name
Sonar.jdbc.password=hehaoyu//Database connection password

sonar.jdbc.url=jdbc:mysql://localhost:3306/oa?useunicode=true&characterencoding=utf8& Rewritebatchedstatements=true&useconfigs=maxperformance//Database links

sonar.jdbc.driverClassName:com.mysql.jdbc.Driver //Database driver


Note: In Sonarqube it is important to note that if you are an Oracle database, you need to add the Oracle JDBC Jar package, the other sonarqube are self-included, not added, Oracle's jar package is in this directory


Step 2: Install Sonar-runner

The same way to extract Sonar-runner to any directory specified, the directory also do not have Chinese, the same is free installation

Link Address: http://www.sonarqube.org/downloads/

Here, Sonar-runner need to configure environment variables, declare a sonar_runner_home variable name, variable value is sonar-runner installation directory, where my variable value is d:\ sonar-runner-dist-2.4\sonar-runner-2.4, everyone corresponding to their own directory modification, and then the path variable name added value%sonar_runner_home%\bin (note that the value of the variable should be separated by semicolons; separate)

Then configure the Sonar-runner configuration file

Click Conf in the Sonar-runner directory to edit the Sonar-runner.properties

sonar.host.url=http://localhost:9000 sonar local IP address

Sonar.jdbc.url=jdbc:mysql://localhost:3306/oa?useunicode=true&characterencoding=utf8 MySQL Local link address

Sonar.jdbc.username=root Database Connection Account
Sonar.jdbc.password=hehaoyu Database Connection password

Sonar.login=admin Sonarqube Platform Login account
Sonar.password=admin sonarqube Platform Login password

Step 3: Create a new sonar-project.properties configuration file in the project root directory at any one you want to test

The inside is written:

# Required Metadata

Sonar.projectkey=monkey

Sonar.projectname=monkey

sonar.projectversion=15.07.28 (recommended version number in this format)

# comma-separated paths to directories with sources (required)

Sonar.sources=src

Sonar.binaries=build (at that time I wrote this (build\classes\) result error, if only write on the build directory will not error)


# Language

Sonar.language=java

# Encoding of the source files

Sonar.sourceencoding=utf-8

Description:sonar.projectkey=monkey

Projectkey and ProjectName as well as the project name, Projectkey and projectname not the same can be written as the purpose of a good distinction

Sources as Source directory

Build to the compiled classes directory,Sonar will automatically traverse all directories

Language for the analysis of the language

Sourceencoding Source code format

Step 4: Execute the command line to generate the results

OA5 is the root directory of the current project

Let the command line enter the directory of the specified project, and then execute the sonar-runner command

( special Note: Because of the command of this form of more, so the habitual sonar-runner written sonar-runner, the middle of a space, when I have not seen what is the reason, Sonar-runner must be next to it)

The success will show

Log back on to the Sonarqube home page and you'll find that the analysis results of one more item on the right

Here's what we want from the analysis results.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Test the Sonar-runner of sonarqube Automation test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.