{"id":19420814,"url":"https://github.com/kazurayam/junit4ks","last_synced_at":"2025-04-24T14:32:32.251Z","repository":{"id":57725851,"uuid":"142514361","full_name":"kazurayam/junit4ks","owner":"kazurayam","description":"JUnit for Katalon Studio. A Groovy class enables you to run JUnit4 for your custom keyword classes in Katalon Studio","archived":false,"fork":false,"pushed_at":"2024-02-22T06:44:41.000Z","size":4451,"stargazers_count":4,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-02-23T01:39:27.849Z","etag":null,"topics":["junit4","katalon-studio"],"latest_commit_sha":null,"homepage":"https://forum.katalon.com/t/junit4-katalon-studio-integration-by-a-built-in-keyword/17637","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kazurayam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-27T01:52:35.000Z","updated_at":"2024-02-23T01:39:27.850Z","dependencies_parsed_at":"2022-09-02T03:41:23.963Z","dependency_job_id":null,"html_url":"https://github.com/kazurayam/junit4ks","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazurayam%2Fjunit4ks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazurayam%2Fjunit4ks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazurayam%2Fjunit4ks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kazurayam%2Fjunit4ks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kazurayam","download_url":"https://codeload.github.com/kazurayam/junit4ks/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223957005,"owners_count":17231550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["junit4","katalon-studio"],"created_at":"2024-11-10T13:25:30.835Z","updated_at":"2024-11-10T13:25:31.258Z","avatar_url":"https://github.com/kazurayam.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"Running JUnit in Katalon Studio\n====\n\nby kazurayam\n- 1st release at 18 July 2018\n- 2nd release at 13 January 2019\n- 3rd release at 10 Feb 2019\n- 4th release at 20 Feb 2019\n- 5th release v1.6.2 at 21 Feb 2024\n\n\n## Problem to solve\n\nI wanted to develop a set of Custom Keywords in a Katalon Studio project. See a post in the Katalon Forum: [Taking entire page screenshot using AShot in Katalon Studio](https://forum.katalon.com/t/taking-entire-page-screenshot-using-ashot-in-katalon-studio/12429) for the background story. My custom keywords were expected to be large and complexed, therefore bug-prone. I wanted to execute thorough unit-testing on my Groovy classes using [JUnit4](https://junit.org/junit4/) framework.\n\n\n## Demo\n\n### Prerequisites\n\n1. Use Katalon Studio version 5.7.0 or higher. I used v5.10.1.\n2. Download the zip file of this project tagged with 1.0 at [Releases](https://github.com/kazurayam/junit4ks/releases) page and unzip it.\n\n### Custom Keywords to test\n\nI made a custom keyword classe. I want to test this using JUnit4:\n\n- [`junittutorial.Calculator`](Keywords/junittutorial/Calculator.groovy) --- calculator which add/subtract/multiply/divide 2 integers\n\n### JUnit Test classes\n\nI made a test classe using JUnit4.\n\n- [`junittutorial.CalculatorTest`](Include/scripts/groovy/junittutorial/CalculatorTest.groovy)\n\n### Test Runner\n\nI made a Test Case in the `\u003cprojectDir\u003e/Test Cases` folder. These test case calls JUnit4, which will run the Test class shown above.\n\n- [`Scripts/test/CalculatorTestRunner`](Scripts/test/junittutorial/CalculatorTestRunner/Script1547192368406.groovy)\n\nThe `CalculatorTestRunner` script is as simple as this:\n\n```\nimport static com.kazurayam.junit4ks.JUnitCustomKeywords.runWithJUnitRunner\n\nimport junittutorial.CalculatorTest\n\nrunWithJUnitRunner(CalculatorTest.class)\n```\n\n### How to run the test\n\nYou can run these test cases just as usual Katalon Studio test case.\n![running a test case](https://kazurayam.github.io/junit4ks/images/running_testcase.png)\n\n\nWhen it finished, you can see the test result output in the Log Viewer and Console in Katalon Studio GUI.\n![testcase execution log](https://kazurayam.github.io/junit4ks/images/testcase_execution_log.png)\n\nYou may expect a report file in XML will be generated, but unfortunately my `junit4ks` does not do it.\n\n## How to apply the junit4ks into your own Katalon projects\n\nYou can download the latest jar file for\n\n- [GitHub Releases page](https://github.com/kazurayam/junit4ks/releases)\n- [Maven Central recpository](https://mvnrepository.com/artifact/com.kazurayam/junit4ks)\n\nDownload the `junit4ks-x.x.x.jar` file and locate it into the `Drivers` folder of your Katalon Studio project.\n\n## API doc\n\nThe groovydoc of junit4ks is [here](https://kazurayam.github.io/junit4ks/api/index.html)\n\n\n## @IgnoreRest\n\nI like 'Spock' because of its @IgnoreRest annotation. I wanted to use @IgnoreRest in my test on JUnit as well. One day I found a nice article:\nhttp://www.qualityontime.eu/articles/technology-stack/toolbox/junit-ignorerest/\n\nI implemented the proposded code into the junit4ks.\n\nSee `Include/scripts/groovy/junittutorial/CalculatorWithIgnoreRestTest.groovy`:\n```\npackage junittutorial\n\nimport static org.hamcrest.CoreMatchers.*\nimport static org.junit.Assert.*\n\nimport org.junit.Test\nimport org.junit.runner.RunWith\nimport org.junit.runners.JUnit4\n\nimport com.kazurayam.junit4ks.IgnoreRestSupportRunner\nimport com.kazurayam.junit4ks.IgnoreRest\n\n@RunWith(IgnoreRestSupportRunner.class)\nclass CalculatorWithIgnoreRestTest {\n\n\t@Test\n\t@IgnoreRest\n\tvoid testMultiply() {\n\t\tint expected = 21\n\t\tint actual = Calculator.multiply(7, 3)\n\t\tassertThat(actual, is(expected))\n\t}\n\n\t@Test\n\tvoid testDivide_wrongType() {\n\t\tdouble expected = 1.5f\n\t\tdouble actual = Calculator.divide(3, 2)\n\t\tassertThat(actual, is(not(expected)))\n\t}\n\n}\n```\n\n\n## Hitory\n\n### JUnit4 was bundled in Katalon Studio\n\nOne day in April 2018 I created a test case of single line:\n```\nimport org.junit.runner.JUnitCore\n```\n\nThis worked! The import statement succeeded. No error was emitted. I realized that the JUnit classes are available in the Katalon Studio's Java VM. Later I found that the Katalon Studio's distribution contains `plugins/org.junit_4.12.0.jar`.\n\n### My first attempt\n\nOK, all I need to know is where to locate test classes, how to activate the runner, and how to report the result. I have done an experiment. I believe I have got a success. Tag [0.2](https://github.com/kazurayam/RunningJUnitInKatalonStudio/tree/0.2) of this repository contains this version of my attempt. This version was created at April 2018.\n\nThe first attempt worked, but I thought the method was too lenghthy and complicated. I wanted to find out an easier one.\n\n### My second attempt\n\nDec 2018, devalex88 (Katalon Developer) proposed a new approach at https://forum.katalon.com/t/how-to-write-katalon-studio-tests-with-intellij-idea-and-other-ides/15940 .\n\nThe idea includes:\n1. Since version 5.7.0, `.classpath` file in a Katalon Studio project contains a line `\u003cclasspathentry kind=\"src\" output=\"bin/groovy\" path=\"Include/scripts/groovy\"/\u003e`. This line defines a build path acknowledged Katalon Studio(=Eclipse). All of `*.groovy` files located in this folder will be compiled (when saved) by the Groovy compiler in Katalon Studio.\n2. It is OK for us to locate `*Test.groovy` files for unit-testing in the `Include/scripts/groovy` folder.\n3. We can use Eclipse to run JUnit. We can open a katalon project with Eclipse (not Katalon Studio)! The built-in feature of Eclipse will look after activating the JUnit tests and reporting the results.\n\nHowever I gave up this approach, because I could not test my custom keyword, within Eclipse, which interacts with web sites via WebDriver. See [this post](https://forum.katalon.com/t/how-to-write-katalon-studio-tests-with-intellij-idea-and-other-ides/15940/27) for detail.\n\n### My third attempt\n\nIn December 2018, I thought that I could test my Custom Keywords using the BDD feature with Cucumber in Katalon Studio. I learned the following manual pages.\n- [Cucumber Features file](https://docs.katalon.com/katalon-studio/docs/cucumber-features-file.html)\n- [Step Definitions](https://docs.katalon.com/katalon-studio/docs/step-definitions.html)\n- [Running Cucumber Features file](https://docs.katalon.com/katalon-studio/docs/running-cucumber-features-file.html)\n\nIt seemed OK. I could nearly achieve what I wanted to do. But unfortunately I was blocked by a defect in Katalon Studio:\n- [The Cucumber version bundled in Katalon Studio 5.10.1 is old, therefore sometimes throws exception](https://forum.katalon.com/t/poor-error-diagnostics-when-cucumber-feature-is-problematic/17474/8)\n\nI could not rely on Cucumber in Katalon Studio.\n\n### My fourth attempt\n\nIn January 2019 I read the source of [`com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords`](https://github.com/katalon-studio/katalon-studio-testing-framework/blob/master/Include/scripts/groovy/com/kms/katalon/core/cucumber/keyword/CucumberBuiltinKeywords.groovy) on GitHub. `CucumberBuiltinKeywords` is the core part of Cucumber-Katalon integration. I studied it to find that **I could mimic that to implement JUnit-Katalon integration**. So I made a new custom keyword class  [`com.kazurayam.ksbackyard.junit.JUnitCustomKeywords`](Keywords/com/kazurayam/ksbackyard/junit/JUnitCustomKeywords.groovy). This looks working fine.\n\nA long and winding road it was. I believe I have found out a satisfactory method to test my custom keywords with JUnit4 within Katalon Studio. I publish it as the 2nd release of [my demo project](https://github.com/kazurayam/RunningJUnitInKatalonStudio/).\n\nLater, 10 Feb 2019, I changed the package name from `com.kazurayam.ksbackyard.junit` to `com.kazurayam.junit4ks`, having \"JUnit4 for Katalon Studio\" in mind, for getting better understood what it is. Also note, @devallex88 made a [contribution](https://github.com/kazurayam/junit4ks/compare/1.4...1.6) to this.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazurayam%2Fjunit4ks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkazurayam%2Fjunit4ks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkazurayam%2Fjunit4ks/lists"}