I have published a project at
This post is just for your interest. No bug report.
Problem to solve
I wanted to develop a set of Custom Keywords in a Katalon Studio project. For the background story, see a post in the Katalon Forum: Taking entire page screenshot using AShot in Katalon Studio. My custom keywords were expected to be large and complexed, therefore bug-prone. I wanted to do unit-testing thoroughly using JUnit 4.
Solution
Unfortunately, Katalon Studio does not offer a toolset to do unit-testing for custom Keywords. Therefore I will invent a framework for myself.
How to inject the Junit4ks files into your own Katlaon project
-
Here I assume you have a Katalon Studio project already created. Any project will do.
-
Visit the Releases v1.6.3 page. Locate the link
injectJunit4ks-build.gradle. Download the file into your projectβs root directory. The file has the following content:
plugins {
id "de.undercouch.download" version "5.7.0"
}
task injectJunit4ks {
doLast {
download.run {
src "https://github.com/kazurayam/junit4ks/releases/download/1.6.3/junit4ks-distribution-1.6.3.zip"
dest layout.buildDirectory.dir('dist-downloaded')
overwrite true
}
copy {
from zipTree(layout.buildDirectory.file("dist-downloaded/junit4ks-distribution-1.6.3.zip"))
into layout.projectDirectory.dir('.')
}
}
}
-
You need to rename the
injectJunit4ks-build.gradlefile tobuild.gradle. -
In a Terminal window, you want to do the following operation in the command line:
$ cd <yourProjecDir>
$ gradle injectJunit4ks
Obviously here I assume you have the Gradle build tool is installed and operational in your environment.
-
The
injectJunit4kstask will unzip the archive and copy the contained files into your own Katalon Studio project. -
Once the zipβs content files have been extracted and injected into your project, the
build.gradleis no longer needed. You should remove thebuild.gradlefile.
You don`t have Gradle on your machine? OK, then you can do the same manually. Download the from the junit4js-distribution-1.6.3.zip, unzip it, copy the folder tree into your Katalon project.
Whatβs in the zip file
Once you ran $ gradle injectJunit4ks task, in your own Katalon Studio project directory, you would find a new file created in the build directory:
$ pwd
$ <yourProjectDir>
$ tree build
build
βββ dist-downloaded
β βββ junit4ks-distribution-1.6.3.zip
The zip file contains the following file tree:
$ tree .
.
βββ Include
β βββ scripts
β βββ groovy
β βββ junittutorial
β βββ CalculatorFailingTest.groovy
β βββ CalculatorTest.groovy
β βββ CalculatorWithIgnoreRestTest.groovy
βββ Keywords
β βββ com
β β βββ kazurayam
β β βββ junit4ks
β β βββ IgnoreRest.groovy
β β βββ IgnoreRestHelper.groovy
β β βββ IgnoreRestRule.groovy
β β βββ IgnoreRestSupportRunner.groovy
β β βββ JUnitCustomKeywords.groovy
β β βββ JUnitRunnerResult.groovy
β β βββ JUnitRunnerResultImpl.groovy
β β βββ LegacyXmlReportGeneratingListener.groovy
β β βββ RunListener4ks.groovy
β βββ junittutorial
β βββ Calculator.groovy
βββ Scripts
β βββ test
β βββ junittutorial
β βββ CalculatorFailingTestRunner
β β βββ Script1751710481301.groovy
β βββ CalculatorTestRunner
β β βββ Script1547192368406.groovy
β βββ CalculatorTestWithIgnoreRestRunner
β βββ Script1552166240495.groovy
βββ Test Cases
β βββ test
β βββ junittutorial
β βββ CalculatorFailingTestRunner.tc
β βββ CalculatorTestRunner.tc
β βββ CalculatorTestWithIgnoreRestRunner.tc
βββ Test Suites
βββ test
βββ junittutorial
βββ runAll.groovy
βββ runAll.ts
----
The *.groovy files under the Keywords directory is the implementation of the junit4ks library.
The files under the Test Cases, Scripts, Test Suite and Include directory are the sample code that utilizes the junit4ks.
How to run the demonstration
Close and reopen your Katalon Studio project in which the junit4ks files have been injected.
Open the Test Suites/test/junittutorial/runAll. Run it it by clicking the green button
. The Test Suite would pass.
When it finished, you can see the test result output in the Log Viewer and Console in Katalon Studio GUI. When any test fails, a Java StackTrace will be printed into the Log Viewer.
You may expect a nicely formatted report file in HTML to be generated, but unfortunately my junit4ks does not do it. In fact, I donβt need it.
Source codes
Have a look at the following sample codes.
The Calculator.groovy is the target class to be unit-tested. The CalculatorTest.groovy carries out unit-tests for the custom class. You can run the test by running the CalcluratorTestRunner in Katalon Studio GUI by clicking the ordinary green button
.
API doc
The groovydoc of junit4ks is here

