JUNIT custom runner does not recognized from Maven test goal - java

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)?

Related

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

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.

Will gradle run Tests annotated with #NotThreadSafe run as a single test process at a time

We have currently set up our application set up with Junit 4 and Maven with the surefire plugin.
Now we are migrating to gradle and we want to run the test case in parallel with the exception of the ones annotated with #NotThreadSafe. Given the long running nature of our test cases it is hard to find out if they are running in parallel or not.
Has anybody used the #NotThreadSafe annotation together with gradle?
In the gradle docs I wasn't able to find out if it is supported or not.

How to run single integration test in maven?

I am trying run single integration test. I have a a lot of *IT class and I want to run only one test. I try this :
mvn -Dit.test=XControllerIT verify
Am I doing wrong? Is there another alternative to this? Maven is being used.
There are two main options depending on your project setup:
Integration Tests are run with a dedicated Failsafe plugin
Integration Tests are run with a regular surefire plugin
If you have a failsafe plugin (and you actually should, its a recommended approach), then use the following snippet:
mvn -Dit.test=MySampleIntegrationTest failsafe:integration-test
If you're on surefire, then run:
mvn -Dtest=MySampleUnitTest surefire:test
In both cases there is a direct plugin goal execution, bypassing the lifecycle like in your initial example (with mvn verify)
In maven it is possible to run the lifecycle, see Default Lifecycle Documentation for more information
Basically, the lifecycle is comprised of phases with plugins bound to each phase
So when you run the mvn verify all the phases before verify will also run.
As a consequence, the code will be compiled (compile phase with a maven compile plugin automatically attached to it will do the job), tests will run (surefire plugin), and so on.
If you don't have a compiled source code and code of tests, you can't use the presented approach because you have to compile the code first.
However, if you already have everything compiled, it makes sense to run only the one test without recompilation of the code, and in this case, depending on the plugin you can use the suggested solution.
Especially it can make sense for local debugging or for CI in some cases multi-step build setup (can be seen in fairly complicated projects)

Is there an equivalent of junit test suite in Scala

In Java, you can create a junit test suites and put all your junit test cases in it. This allows you to run all your test cases all at once and get the testing results immediately (e.g. how many tests passsed and failed, and which tests failed). Is there something equivalent in Scala within the ScalaTest?
Thanks
I don't know if there's anything equivalent for ScalaTest but in general this is a bad idea. It requires you to keep your test suite class up to date when you add new tests. Both your IDE and your build tool should let you be able to automatically discover and run all tests at once.
If you're using maven or gradle, just placing all your tests under the src/test/scala directory should be enough that running the test target will execute all test

How can I run all JUnit tests in one package # NetBeans?

I have like trillion test packages with bazillion tests and I want to run just some of packages. Now I must run whole project (some tests takes long to complete) or I need to run every single file manually. How is possible to run just some packages in NetBeans ? I can't find this option ...
It's probably not what you want, but the NetBeans help topic, Running a JUnit Test, says:
If you want to run a subset of the
project's tests or run the tests in a
specific order, you can create test
suites that specify the tests to run
as part of that suite. After creating
a test suite you run the suite in the
same way you run a single test class.
Creating a test suite is covered in the topic Creating a JUnit Test.
If you use JUnit 4 then try ClasspathSuite and its regex filters.

Categories