Use Karate framework with Fail Safe and Sure Fire plugin [duplicate] - java

Is there a way to run Karate test during maven's integration test phase? It seems that surefire plugin is hardcoded into Karate. I have tried to override it using failsafe plugin but with no luck. I don't want test to run along with unit tests.
Thank in advance!

It seems that surefire plugin is hardcoded into Karate
I'm not sure where you got that impression, but no, the surefire plugin is not hardcoded into Karate.
Keep in mind that the simplest way to not run a JUnit test via surefire is to not use the *Test.java naming convention.
I think the solution for you is simple, whichever JUnit test is the "entry-point" for your Karate tests (the parallel runner is recommended) - just use the failsafe naming conventions.
And then, just include the failsafe plugin as per the examples and it should work. If you have trouble getting that to work (unlikely), then you should look at maven profiles.
EDIT: also see this comment: Is there a way to run Karate tests as an integration test suite against a pre-booted spring boot server?
Turns out that I cannot be done and it is a limitation of Maven, not Karate. Howto add another test source folder to Maven and compile it to a separate folder? - Here is my test project to prove it out: https://github.com/djangofan/spring-boot-hello - Thanks for leading me down what appears to have been the correct path to discover the limitation. Using Gradle would likely solve my issue but that is not an option on my project. If I use Karate for "separated integration tests", I need a separate mvn test module.

Related

'maven test' is only for Java

I am developing in not common language (IBM SQL PL) and I want to integrate the unit system framework of that language into the lifecycle of Maven.
I would like to know how the command maven test works. It seems that the normal execution is only for Java, because the three SurefireProviders are jUnit3, jUnit4 and TestNG. The SurefireProvider documentation does not explain nor gives indications about other providers for different programming languages.
I can also configure the execution of my programming language tests into the test phase, but I do not know the side effects. This is explained here: https://stackoverflow.com/a/19356216/456274
In conclusion, what is the best way to integrate unit test report into maven test execution and be part of the lifecycle to include that into a continuous integration?
There are similar and more common issues for developers who want to test their javascript code with maven.
You should write your own maven plugin which integrates your unit testing framework to maven lifecycle: http://maven.apache.org/guides/plugin/guide-java-plugin-development.html
A good example is the Jasmine Maven Plugin which integrate jasmine, a unit testing framework for javascript: http://searls.github.io/jasmine-maven-plugin/
Then, by adding your custom maven plugin in test goal, your "mvn test" command will invoke it.

What is the process with Maven project to compile and test the code?

I have maven project imported in my eclipse. Now I need to start making changes to it and test it with the integration test (out of App server). Currently, the integration test is run out of server using openEJB container.
My basic question is, what is the regular process to compile, build and test with Maven?
mvn install
Maven -> Update Project.
Run my test from command line
Is it how it is done? I am specifically interested in knowing mvn install commands.
So should I do all three steps before I can test it?
Example: I just wanted to print something and see what is the output. For this I guess I need to do all these steps?
The openEJB container needs classes so it can load them.
There is a wonderful Maven quick-reference sheet at http://maven.apache.org/guides/MavenQuickReferenceCard.pdf
First, you should be aware that unit tests and integration tests are separate and are run from separate plugins and at separate parts of the maven lifecycles. Unit tests are run with surefire and integration tests are run with failsafe.
You want to run integration tests and the failsafe documentation says:
NOTE: when running integration tests, you should invoke maven with the (shorter to type too)
mvn verify
rather than trying to invoke the integration-test phase directly...
This is the best way to run integration tests directly in maven. It will run all the preceding steps necessary (eg: compile) in order to run the integration tests. It won't waste time doing an install because install happens immediately after verify.
But if you're running the tests locally, it may be a better idea to run your integration tests directly in your IDE. That will give you a much faster feedback loop.
If it is Eclipse project the most reasonable thing is to do everything not from command line but from Eclipse. Assuming you have m2e plugin installed, go to your_project->run as->Maven test and run it.
You dont need neither install nor package phase to run Maven tests, package will create a jar which is not needed for tests, install will copy this jar to local repo which is also useless. When Maven run tests it uses compiled classes from target dir and ignores project's jar if even it exists.
Yes, mvn isntall is the most popular option. It compiles, packages and tests your project.

How to collect statistics about java integration tests

My development environment includes Maven, Failsafe and Spring testing IS (AbstractJUnit4SpringContextTests).
I'm looking for a way to collect statistics about the integration tests run.
Information such as Test duration, process memory, etc...
What is the best way to collect such information with the above configuration (and to integrate with the maven flow).
as far as i recall, the surefire plugin is able to write reports to some directory (which will be used by e.g. jenkins to present results)
There is a maven plugin for Sonar. It is highly configurable, maybe solution to your problem.
The failsafe plugin generates a xml file with the tests result. this can be used, for example by a jenkins plugin.

how to configure java junit with Teamcity?

Can somebody please tell me how to integrate java JUnit with TeamCity?
You can use the jUnit task in your Ant script that you have TeamCity run.
Current Teamcity version doesn't provide separate JUnit build step.
I guess it's because of test classpath determination problem.
You may provide classpath explicitly with ant junit task.
Or Teamcity can fetch test classpath from IDEA or IPR project. These two links explain how to run junit tests as part of compile build step.

JUNIT custom runner does not recognized from Maven test goal

I have custom runner of JUNIT, run with annotation:
#RunWith(SomeClass.class)
When running maven goal test it does not run it.
What should be done? is it configurable?
Most likely the problem isn't related to #RunWith; otherwise you should at least get an error. Does the test class match one of Maven's (Surefire's) naming patterns for test classes (e.g. **/*Test.java)?

Categories