In the good old days, automation scripts were mostly record and playback! That was because most of the people who were doing automation were manual testers turned into automation engineers. It was rare to see a a good framework for automated testing. Now situation is completely different. Thanks to DevOps process – everyone understands the importance of automated testing. Nowadays, automation engineers use most of the tools available for Dev/SysAdmin to improve the QA process. We use Jenkins, Git, Docker etc.
We follow all the design principles and patterns for writing our selenium scripts to keep our maintenance effort under control and ensure that our test scripts are following certain standards.
In this article, we are going to take a look at SonarQube – a tool continuously inspects the code we push to GitHub/Version control to ensure that our test script quality is good! Using SonarQube for inspecting our automation scripts brings several advantages. Some of them are listed here.
- Raises the code quality
- Detects the duplicate code
- Ensures that Dev coding standards are being followed
- Detects any potential issues with the test scripts / logic issues etc
Setting Up SonarQube:
You can visit the official site and check the install instruction if you do not use Docker. I am going to use Docker! Setting up any tool is now easy with Docker.
- Create a directory
- Under the directory, create a file – docker-compose.yml with below content.
docker-compose up -d
- That command will download all the necessary docker images and bring SonarQube server up and running at port 9000.
You can login with default username and password.
- username: admin
- password: admin
- Create a token for your project.
- Copy the command which is displayed on the right side.
- Once we copied, you can close that dialog. We would see below screen. We have not analysed any projects so far.
- We need to run the command in the machine where we build our project. Modify the copied command from the previous step, slightly as shown here.
- SonarQube requires compiled code for Java. So we add the ‘clean compile‘ command
- If SonarQube is running in a different machine, then update the command with the IP address of the SonarQube machine.
- We also include our classes under test directory
mvn clean compile \
- That’s it. It will compile, inspects the sources and push the results to SonarQube.
- After refreshing the screen, We can see results as shown here.
Our selenium test scripts might not go to production! But it ensures that only high quality product is shipped into Production. As our selenium scripts have big responsibility of verifying the code created by developers, It is important for our test scripts to meet industry quality standards 🙂 SonarQube helps us to meet the code quality.
Happy Testing and Subscribe 🙂