How to run Karate with a Junit runner without using Maven

Viewed 345

We rely heavily on logic in our Junit runner and currently call into it with mvn test

The logic mainly consists of

  1. Instantiating a RuntimeHook and binding it to Runner.Builder().hook if an appropriate JVM switch is specified on the command line.
  2. Calling Runner.Builder().clientFactory() with a mock, again if an appropriate JVM switch is specified on the command line.
  3. Last setting minor things like Runner.Builder().tags and Runner.Builder().path

All of this works perfect today. Our main gripe however is Maven is slow.

Is there a way to accomplish the above logic and run without the expensive build time of Maven?

1 Answers

Since you are mixing a bit of Java code, I think you are going to depend on Maven for build + dependencies. That said, there are ways to ask Maven to dump all JAR dependencies into a text file. For example:

mvn dependency:build-classpath -Dmdep.includeScope=test -Dmdep.outputFile=classpath.txt

And then you may be able to shape a command that uses the java binary directly and you probably already know that com.intuit.karate.Main supports all the extension things. The bad news is I don't think we support things like the custom HTTP Client yet, you can see this PR where someone did this for the RuntimeHook. Perhaps you can contribute. Or maybe you have logic in Java code anyway, so calling the Karate Runner directly may be the way to go.

I think maybe the solution you will land on is mvnd - I haven't used it yet, but I'm hearing very good things on Twitter from some experienced Java folks I follow.

Related