I can't run unit tests with JUnit in Katalon Studio

When I want to run a test class I get the following error:

1 Like

Have a read of the below link:

1 Like

I saw the project, and it’s very interesting, but Is there an easier way? :disappointed_relieved:

Here is something that Bing’s AI has to “say” (note that it could be lying through its teeth) .
:slight_smile: : I’m going to suggest you do more reading of Katalon’s documentation.

Certainly! Katalon Studio is a powerful tool for automated testing, and it supports running JUnit tests. Let me guide you on how to set up and execute JUnit tests within Katalon Studio.

  1. JUnit in Katalon Studio:
  • Katalon Studio allows you to integrate JUnit tests into your test automation projects. You can use JUnit to perform unit testing on your custom keywords, Groovy classes, and methods.
  • To get started, create a custom keyword that enables you to run JUnit4 tests within Katalon Studio. You can find a demo project on GitHub that demonstrates this: JUnit for Katalon Studio.
  • The custom keyword, JUnitCustomKeywords.runWithJUnitRunner, executes your JUnit-based tests. These tests interact with external websites via WebDriver and are backed by the Katalon Studio runtime environment.
  • The test results are visible in the Log Viewer and Console within the Katalon Studio GUI1.
  1. Steps to Set Up JUnit Tests in Katalon Studio:
  • Create a custom keyword that calls the JUnit API to execute your unit tests.
  • Place your application classes (to be tested) in the Keywords directory.
  • Store your test classes in the Include/scripts/groovy directory.
  • Write a simple test runner in a Katalon Studio test case. For example:
import static com.kazurayam.junit4ks.JUnitCustomKeywords.runWithJUnitRunner
import junittutorial.CalculatorTest

  1. Reporting and Integration:

Remember, this approach allows you to leverage the power of JUnit while benefiting from Katalon Studio’s features and runtime environment. Happy testing! :rocket::mag::test_tube:

I am the author of com.kazurayam.junitks.JUnitCustomKeywords class.

These sentences do not apply to the com.kazurayam.junitks.JUnitCustomKeywords class. Yes, the runWithJUnitRunner method will report logs in the Log Viewer and Console. But it does NOT compile any report as a file. It does not compile so-called JUnitReports in XML.

1 Like

In another recent post by @lfilipovi, I reported a bug of Katalon Studio’s capability to run JUnit tests.

Please have a look.


I am rather afraid that you would have hard time in developing JUnit tests in Katalon Studio.

1 Like


I DO NOT RECOMMEND you to develop & run JUnit4 tests in Katalon studio.

But I (@kazurayam) developed the com.kazurayam.junit4ks.JUnitCustomKeywords class 5 years ago? Why?

— I did not aim to write any Web UI automated tests with JUnit in Katalon Studio. I wanted to write some unit tests for my own Custom Keywords in Katalon Studio with JUnit.

You may or may not be aware, Katalon Studio provides no support for unit-testing your Custom Keywords. In token of that, Katalon’s documentation has no section titled “How to test your Custom Keywords”. Katalon assumes that your Custom Keywords are born bug-free automagically.

I can not develop my custom classes bug-free automagically. Therefore I had to invent a way for myself. So I developed my library.

Let me introduce my Custom Keywords ExecutionProfilesLoader to you as an example, which is runnable in Katalon Studio and which I unit-tested with JUnit.

I developed com.kazurayam.ks.globalvariable.ExecutionProfilesLoader class in Katalon Studio because this class had to be executable in Katalon Studio. At the same time, the ExecutionProfilesLoader was complicated enough so that it deserved a set of thorough unit-tests. Therefore I wrote a set of unit-tests for the ExecutionProfilesLoader keyword with com.kazurayam.junit4ks.JUnitCustomKeywords.

I never use JUnit in Katalon Studio for automated UI testing.

If you are going to develop WebUI automated test with JUnit, I think it is a poor idea to do it in Katalon Studio. Other ordinary IDEs (JetBrain IDEA, Eclipse, etc) on top of Gradle or Maven with pure Selenium WebDriver + JUnit4 or JUnit5 — these environments are far more comfortable, well-tested, robust and bug-free to work on JUnit tests than in Katalon Studio. The following book gives you a thorough tutorials.

1 Like

Stick to Junit!
Why am I saying this?
For few reasons …

Katalon use own implementations and concept regarding what a test-case, a test-suite means.
If the user need is migrate from Junit, TestNG or whatever other framework then some manual work is needed.
TestCases, Suites and so on must be re-written, simply importing the code and expect magic won’t work.
You have to ‘import’ the code by manually copy paste and addapt it as katalon testcases.
There was a brief video-tutorial somewhwere on how this may be achieved and steps involved, I cannot find it anymore.
Feel free to search for it.

The reason for using Junit, TestNG or whatever other framework with Katalon may have the only sense if you would like to do some unittests for your own develloped classes / keywords and eventually validate those without using KRE.

This has been briefly debated in:

… and the efforts made by @kazurayam are, for my eyes, more or less for same reasons.

Hope this helps!

Do not try to run JUnit tests inside Katalon Studio.

Do it in IntelliJ IDEA, Eclipse or whatever IDE you are currently working on. That is the easiest way. See the following tutorials for example


Yes, I have been use JUnit inside IntelliJ and It’s very helpful, but In my job I have to use Katalon, I wanted to know how implement unit testing in my custom keywords

How about then continue to use JUnit inside IntelliJ but with Katalon, then use it as it can be used…

Is this a JUnit course for school?

Your new “custom keywords” — there could be 2 types.

  1. classes that are dependent on the Katalon API com.kms.katalon.core.*
  2. classes that are independent of the Katalon API

You desperately need to work inside Katalon Studio to develop the type 1 classes because Katalon’s jar files are bundled inside the Katalon’s products (Katalon Studio, Katalon Runtime Engine) only; the jar files are not downloadable from any public maven repositories. KS is not open-sourced.

However you do not need Katalon Studio to develop the type 2 classes. You can develop your classes in IntelliJ IDEA while testing them with JUnit, build a jar using Gradle. Then you can import the jar into the Drivers folder of your target Katalon projects as documented at the doc.

I have developed a lot of Katalon-independent libraries in IntelliJ IDEA and import them into my katalon projects. For example, I use the following:


These projects are independent of the Katalon API, so I developed them as an isolated project in IntelliJ IDEA with Gradle where I performed unit-tests with JUnit5 Jupyter.

Based on my previous experience, I think that the significant portions of my “custom classes” are Katalon-API-independent so that I can develop them outside KS. I always try to minimize the size of the com.kms.katalon.* dependent classes.

You can reuse your jar file(s) in your multiple Katalon projects easily. Therefore it is a good idea to seperate projects outside of Katalon Studio. You may or may not be aware, when you have a set of custom Groovy classes contained inside a Katalon project A, it is very difficult to reuse the code set in another Katalon project B and C. Though Katalon representatives may proudly say “we offer the Import and export keywords in Katalon Studio is available”. Well, I see it a fake.

I would highly recommend you to seperate your codes into 2 portions: com.kms.katalon-dependent portions and independent portions. I think that the KS-dependent portions can be very thin, which only does calling Katalon API to pass information to/from your externally developed library. Most of the business logic could be isolated from the KS-API. In short, I never use KS to implement the codes for complexed logics at all. I always do it in IDEA.

You would rarely need JUnit for the thin portions which are left inside KS. You can write some simple Test Cases that call your KS-API-dependent Keywords to check if the keywords run or not. You won’t need JUnit for it.

1 Like

It those are indeed unittests (written to test some custom clases you wrote) and your custom classes do not depend on Katalon specific imports than you can store them in your Katalon project but do not run them with katalon.
Just run them as a maven goal or with gradle.
See for example an introductory tutorial for junit5 and gradle:

This is why command line tools exist. To decouple your work from specific IDE’s features.
You can store also gradlewrapper in your project to decouple it even more from specific environments (different maven or gradle version may lead to different results)

1 Like

Unfortunately, this tutorial would not apply to a Katalon Studio project straight forward. I would explain why.

Gradle/Maven has its standard directroy structure for the Groovy program source codes, which looks


Gradle build system assumes that this starndard directory structure is applied to your project as default. If your project has different directory structure, you need to explicitly declare the source code directory structure.

As you already know, Katalon Studio has its unique directory structure, like


This structure is completely different from the Gradle/Maven’s standard directory strucuture. This difference makes your life as a Gradle/Maven user very challenging. You have to wrote code in the build.gradle file to declare how your custom directory structure looks like so that the Groovy/Java compilers can accept your source codes. Where to locate the .class files? The .class files will be generated by your unique build system, but the .class files must be accessible for Katalon Studio runtime. This is another difficult issue. How to resolve external dependencies? This is another issue to be resolved.

The build tools Gradle/Maven are really large and complicated software. The documation has hundreds of pages. It is difficult to learn enough and find some solutions for your non-typical usages. I am sure that this lesson would be much harder than using my com.kazurayam.junit4ks.JUnitCustomKeywords class.

Why Katalon project is designed to have unique directory structure which is different from the Gradle/Maven’s standard one? — I guess that the developers of the original Katalon Studio software a decade ago did not use Gradle/Maven at all. That’s all.

That’s a very basic tutorial. Anyway, with gradle or maven one can specify the src and test paths easily.
there are plenty examples on stackoverflow

Not easy at all. If you try to, you will encounter a lot of myterious error messages …

Yes, there are plenty of Gradle/Maven build examples that conform to the starndard directory structure. But I have never seen any examples of Gradle build that uses non-standard source code directories.

Well, the ‘easiness’ level is dependant on the user determination :slight_smile:
And, as i mentioned, one of the conditions is to not use Katalon specific imports in such custom classes, so the deps can be solved from maven central.
For the rest, will be the same as using IDEA from Intelij, or Eclipse or whatever, same steps needed.


I am trying to use the plug in you developed, I downloaded the .jar and put it in the project libraries, but when I try to run the test case I get an error.

Test case:



Caught: java.lang.NoSuchMethodError: 'java.lang.Object org.codehaus.groovy.runtime.memoize.EvictableCache.getAndPut(java.lang.Object, org.codehaus.groovy.runtime.memoize.MemoizeCache$ValueProvider)'
java.lang.NoSuchMethodError: 'java.lang.Object org.codehaus.groovy.runtime.memoize.EvictableCache.getAndPut(java.lang.Object, org.codehaus.groovy.runtime.memoize.MemoizeCache$ValueProvider)'
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Please show the FULL stacktrace message; Don’t trim. I need to see all lines.

I have never seen such Exception.

org.codehaus.groovy.runtime.memoize.EvictableCache ? I have never seen this class name.

I guess that your Katalon project is running in an environment where 2 or more different versions of Groovy accessible for your code. Version conflicts could cause anything mysterious.

You should try the same in a clean environment.