Applying Code Linting in Test Automation Frameworks

The QA team should use one of the linter e.g. checkstyle to apply a coding standard in the Automation framework.

This helps us keep the code clean and consistent, make pull requests shorter and easier, overall saving us time.

How to run the linter
Yo…


This content originally appeared on DEV Community and was authored by Raghwendra Sonu

The QA team should use one of the linter e.g. checkstyle to apply a coding standard in the Automation framework.

This helps us keep the code clean and consistent, make pull requests shorter and easier, overall saving us time.

How to run the linter
You can run the linter at any time with mvn checkstyle:checkstyle. This will log any errors. It will also generate a html report in the project folder which is at /target/site/checkstyle.html.

Use the git hook
To use this you need to run this command - git config core.hooksPath .githooks so that git looks in the .githooks folder in the project for hooks.

https://github.com/raghwendra-sonu/GitHooks

Once you run this, from then on the linter will run automatically before a commit.

Optional Intellij plugin
There is an Intellij plugin for checkstyle too.
Add it by clicking Preferences → Plugins , search for “checkstyle” and install CheckStyle-IDEA plugin
Once it’s installed you need to configure it - Preferences → Tools → Checkstyle. Select our custom checkstyle.xml file [The xml file is in the root of the project]:

image

Now you will have a checkstyle tool window at the bottom of your IDE.

Use the checkstyle file as a formatter scheme
This is another optional but helpful step.

You can avoid any linter errors by importing our checkstyle file as a scheme in Intellij’s code formatter.

To use it click Preferences → Editor → Code Style → Java

Click the cog button then Import Scheme → Checkstyle Configuration then select the checkstyle.xml file:
image

Now when you generate new code or format existing code it will apply the linter rules to it. To format your code just select the code/files then click Code → Reformat Code.


This content originally appeared on DEV Community and was authored by Raghwendra Sonu


Print Share Comment Cite Upload Translate Updates
APA

Raghwendra Sonu | Sciencx (2021-05-22T05:52:48+00:00) Applying Code Linting in Test Automation Frameworks. Retrieved from https://www.scien.cx/2021/05/22/applying-code-linting-in-test-automation-frameworks/

MLA
" » Applying Code Linting in Test Automation Frameworks." Raghwendra Sonu | Sciencx - Saturday May 22, 2021, https://www.scien.cx/2021/05/22/applying-code-linting-in-test-automation-frameworks/
HARVARD
Raghwendra Sonu | Sciencx Saturday May 22, 2021 » Applying Code Linting in Test Automation Frameworks., viewed ,<https://www.scien.cx/2021/05/22/applying-code-linting-in-test-automation-frameworks/>
VANCOUVER
Raghwendra Sonu | Sciencx - » Applying Code Linting in Test Automation Frameworks. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/22/applying-code-linting-in-test-automation-frameworks/
CHICAGO
" » Applying Code Linting in Test Automation Frameworks." Raghwendra Sonu | Sciencx - Accessed . https://www.scien.cx/2021/05/22/applying-code-linting-in-test-automation-frameworks/
IEEE
" » Applying Code Linting in Test Automation Frameworks." Raghwendra Sonu | Sciencx [Online]. Available: https://www.scien.cx/2021/05/22/applying-code-linting-in-test-automation-frameworks/. [Accessed: ]
rf:citation
» Applying Code Linting in Test Automation Frameworks | Raghwendra Sonu | Sciencx | https://www.scien.cx/2021/05/22/applying-code-linting-in-test-automation-frameworks/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.