4

The Karate docs have 2 examples of testing with Karate and JUnit5:

I created a project using only karate-core (0.9.9-RC2) with the second example and don't need karate-junit5. What is the difference?

I'm very impressed with what Karate is offering and I'm interested in creating a test harness that could need to pick tests out according to runtime criteria and will also need custom reporting so I'm looking at the easiest ways of hooking into the test runner. The code in karate-junit5 seems a good starting point but I just want to understand why it is not actually necessary for normally running tests.

1 Answer 1

3

Great question and I can answer this. You are right, directly using the Runner class is sufficient, and this is the only way to run tests in parallel.

However, if you use the JUnit runner you get the "green bar" experience you are used to as a Java developer and we make sure the IDE UI (e.g the tree-view of tests run and failures etc) is populated. In IntelliJ you even see the logs when you click on one of the "test case" nodes if I remember right.

EDIT: note that I mean here you can see the data of each Scenario in the IDE, not the Java class of the containing JUnit test. Screenshot of IntelliJ below. So this can be convenient to quickly see what failed and the corresponding error message without having to dive into logs / HTML reports:

enter image description here

But once you get used to looking at the HTML reports that Karate outputs, in my opinion - you don't need the JUnit integration.

To summarize: the JUnit support is

a) because we started as a Cucumber extension (there is even a @KarateOptions annotation that is being deprecated)

b) because some folks like the IDE integration + experience and it is useful to run "one test at a time" in dev-mode

Your comment makes me more convinced that we can eventually deprecate the JUnit support. Would be good to get your feedback on this once you have had a chance to play around more.

5
  • 1
    Thanks for the helpful and fast response. I'm returning to Java after a few years away so have no prior expectations. It seems that I get the IDE integration and ability to run individual tests without the junit5 package anyway which is valuable - is there something I am missing by not using karate-junit5? Jan 5, 2021 at 11:59
  • 1
    Also, to dynamically control the features being run could I use JUnit5's dynamic tests? This is why I was looking at the karate-junit5 code but perhaps I can do something in the TestRunner example you provided and look at the ReportUtils example for output. Does that sound right? Thanks. Jan 5, 2021 at 12:01
  • 1
    @PeteEdwards to dynamically control features, you can pass a custom list of files to the Runner here's an example: github.com/intuit/karate/blob/develop/karate-demo/src/test/java/… - I edited my answer for your question on IDE support Jan 5, 2021 at 12:05
  • @PeteEdwards thanks I realized I missed the key part - that the Karate JUnit support surfaces the data about each Scenario in the IDE. this can be useful to quickly see what failed and the corresponding error message without having to dive into logs / HTML reports Jan 5, 2021 at 12:12
  • 1
    That really helps - I see now that the integration converts each Scenario to a separate test to surface that data so a best of both worlds would be a parallel runner that supported this integration. For now I think I could keep both styles of runner - one for development and the other for the full test harness. Your input has really helped me understand the differences. Thanks. Jan 5, 2021 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.