Static code analysis examines code without running it to catch errors, standards violations, and security issues. Learn why it matters for test automation code and how to run CodeNarc on your Katalon Studio scripts with Gradle.
In today's fast-paced software development environment, ensuring the quality and security of code is paramount. Static Code Analysis has emerged as a vital practice in this realm, offering a systematic method to examine code without the need to execute it. In this blog, you will delve into the essence of Static Code Analysis, its applicability, and the significant benefits it offers, particularly in the context of testing code. You will also be guided through performing Static Code Analysis on test scripts using CodeNarc in Katalon Studio.
What is static code analysis?
Static code analysis is a method of examining the written software code without executing the program. The result of the examination provides an understanding of the code structure, coding practices, vulnerabilities, and adherence to industry standards.
Static analysis covers the following during examination:
- Programming errors
- Coding standard violations
- Undefined values
- Syntax violations
- Security vulnerabilities
Who does static code analysis?
Static code analysis has been standard practice in software engineering for decades, and QA teams are now adopting it to screen their test automation code too.
Why should test code be screened with static code analysis?
There are a couple of benefits that Static Code Analysis can provide for testing code:
- More performant scripts, because engineers are pushed to fix inefficient code, which speeds up automation and reduces memory and processing use.
- More readable code when it’s reviewed, maintained, or reused by someone other than the author.
- Easier, faster debugging, with unused statements flagged for removal.
How to perform static code analysis on test code
Generally, Static Code Analysis is performed by a variety of tools including open-source options. The options vary based on the language used and the type of analysis on which the emphasis would be.
Since Katalon Studio uses Groovy as its scripting language, several proprietary and open-source tools are compatible with it. Here, you will use CodeNarc, a static analysis tool for the Groovy language.
Here are the steps:
- Create a project with the Generate build.gradle file option checked.
- In the project folder, open the build.gradle file and add the CodeNarc dependency and task. The complete file is below:
plugins {
id 'java'
id 'groovy'
id 'com.katalon.gradle-plugin' version '0.1.1'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.codenarc:CodeNarc:3.4.0'
}
tasks.register('runCodeNarc', JavaExec) {
mainClass = 'org.codenarc.CodeNarc'
classpath = sourceSets.main.runtimeClasspath
args '-rulesetfiles=file:codenarc.ruleset'
args '-includes=Scripts/**/*.groovy,Keywords/**/*.groovy'
}3. Go to the CodeNarc website to download the available ruleset from the link here. Once downloaded rename the file to “codenarc.ruleset” and move it to the Katalon project folder where you have build.gradle file.
Sample ruleset file:

- Open a terminal and
cdto the Katalon project folder. Then rungradle runCodeNarc(replace runCodeNarc with the task name you defined). Once the job runs successfully, you should find CodeNarcReport.html in the project folder, along with build.gradle and codenarc.ruleset.
Sample report:
- Visit the CodeNarc website to learn more about custom rules and rulesets.
Conclusion
Static code analysis is an important practice in modern software development, improving code quality, performance, and security. By adding tools like CodeNarc to your workflow, you can keep your test automation scripts performant, maintainable, and secure, which leads to more reliable software and smoother development and QA processes.
Frequently asked questions
It’s a method of examining software code without executing it to understand structure, coding practices, vulnerabilities, and adherence to standards.
It can surface programming errors, coding standard violations, undefined values, syntax violations, and security vulnerabilities.
The content lists benefits like improving performance (less memory/processing), improving readability for maintainers, making debugging easier, and forcing removal of unused statements.
It focuses on CodeNarc, since Katalon Studio uses Groovy and CodeNarc is a static analysis tool for Groovy.
After setting up build.gradle and adding a ruleset file (codenarc.ruleset), you run gradle runCodeNarc; a successful run generates CodeNarcReport.html in the project folder.

Test everything. Ship with confidence.
From generating test cases to spotting failures, Katalon's AI works across your entire pipeline, automatically.




