2
votes

Karate suggests that to run all tests in a CI environment, a *Test.java file should be added above the feature files (in hierarchy) and then run using - mvn test command. I am using my Runner.java file to create test data before the tests are run and then do a clean up. I run this runner file in IDE and everything runs fine - the data is created, all feature files in the same package run and then clean-up is performed. The reason i used the Runner file to create data is because i using karate itself to create test data and the Runner file passes some information on created data to the feature files to run api tests. I had earlier posted a question regarding how to achieve this, please refer to this answer - https://stackoverflow.com/a/55931786/4741035

So now I have a *Test.java file in my project which i run using - mvn test. This runs all the feature files and tests fails as the Runner.java is not executed at all.

Why doesn't karate run the Runner file, if it is present first that the feature files?

Help is much appreciated.

1
Could you create a minimal running example?Peter

1 Answers

1
votes

If you are trying to run something "once" before all your tests, use karate.callSingle() documented here: https://github.com/intuit/karate#hooks

var result = karate.callSingle('classpath:demo/headers/common-noheaders.feature', config);

And in the above feature (or JS) you can call Java code using Java interop.

By the way I don't agree with the answer you linked because of the above approaches.