I have made a demo project and published it on GitHub:
Background
I am going to develop a custom Keyword in a Katalon Studio project. See a post in the Katalon forum for the background story. My custom keyword is expected to be fairly large, complicated, and therefore bug-prone. So I want to execute thorough unit-testing on my Groovy classes and methods with JUnit4 in Katalon Studio.
I was aware that the Katalon Studio’s distributed zip file contains plugins/org.junit_4.12.0.jar
. I tried a test case of single line:
import org.junit.runner.JUnitCore
This worked! I mean, import statement succeeded, no error emitted. I realized that the JUnit classes are available in the Katalon Studio’s Java VM.
OK, all I need to know is as follows
- where to locate the application classes to be tested
- where to locate the test classes using JUnit API
- where to locate the test-runner scripts
- how to write a junit-test-runner that executes the test-runner scripts
- how to report the test result. I want to read the messages in the Log Viewer of Katalon Studio
Solution
I have done an experiment. I believe I have got a success.
-
where to locate application classes? — in the
Keywords
directory -
where to locate test classes? — in the
Include/scripts/groovy
directory -
where to locate test-runners? — in the
Test Cases/test
directory
- how to write a test-runner? — I want to create a Test Case which performs the role of junit test-runner. It is as simple as:
import static com.kazurayam.junit4ks.JUnitCustomKeywords.runWithJUnitRunner
import junittutorial.CalculatorTest
runWithJUnitRunner(CalculatorTest.class)
I will develop a new Groovy class
-
com.kazurayam.junit4ks.JUnitCustomKeywords.runWithJUnitRunner
which calls the JUnit API to execute the unit tests.
- how to report the test result
— The Test Case as “JUnit Test-Runner” will report log in the LogViewer and the Console as usual.