Why does Surefire fail to pick up my JUnit 5 tests in Quarkus and starting from version 3.0.0-M5 - junit5

In my Quarkus project I work with a stock standard Quarkus setup of a project (https://code.quarkus.io/) and some internal libraries that rule JUnit 5 dependencies we use in all out projects. When I switch to using Surefire 3.0.0-M5 (or higher) I keep on bumping into that fact that Surefire does not pick up the JUnit 5 tests. When I add a JUnit 4 test (just to test) it does get picked up and executed.
Can anyone help out, please?

Via the release notes of Surefire 3.0.0-M6 I bumped into SUREFIRE-2036 which revered to SUREFIRE-2033 which mentioned that I might have a superfluous dependency on junit-platform-runner on my classpath. When I removed this dependency (using an exclude on the transitive dependency from the internal library): JUnit 5 tests were executed again.

Related

EclipseLink Static Weaving with Intellij

I'm using IntelliJ and I want my unit tests to be run or debug with static weaving for lazy loading et al. I know that unlike Eclipse that IntelliJ does not have a static weaving step but I imagine someone must have setup IntelliJ to statically weave before running or debugging tests.
So far I have tried dynamic weaving with the JVM argument of -javaagent:./path/eclipselink-2.5.0.jar but that doesn't seem to work. I still get these warnings:
[EL Warning]: metadata: 2013-08-28 11:00:51.091--ServerSession(1610028911)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [owner] for the entity class [class com.my.Contact] since weaving was not enabled or did not occur.
Do my IntelliJ brother and sisters just punt on this and skip weaving in the IDE? Do we just not use EclipseLink or have we figured out how to handle the static weaving and still use IntelliJ?
Thanks!
You can create additional build steps before launching a run configuration.
Run > Edit Configurations…
Select the desired run configuration
Add your static weaver compiler as additional build step under `Before Launch:
For example add a Maven goal like eclipselink:weave
Or execute a java process like java org.eclipse.persistence.tools.weaving.jpa.StaticWeave…
Position should be between Build and `Build artifact``
See Screenshot:
Another solution is to define the Maven goal as a hook for After Build in the Maven tool window. Just right-click on the appropriate Maven goal and select Execute After Build. This will execute the EclipseLink Weaver via Maven everytime after Build is executed. You will see the hook in parenthesis behind the Maven goal:
IntelliJ Idea can run additional targets to build the application.
If you have an maven project with staticweave plugin configured, it is possible to add a maven "process-classes" goal to perform staticweave actions automatically on idea build run.

How to avoid maven compiling testClass in normale compiling

I have a default maven project:
/src/main/java
/src/test/java (include *Test.java).
When I exeucte "mvn compile", maven also tries to compile the testClasses under /src/test/java. This fails, as of some dependencies such as JUnit are under "test"-scope. Changing the scope of e.g. JUnit to "provided" everything works fine.
How can I avoid maven to compile testClasses when compiling? In my understanding, I expect to maven to compile this files only when executing "testcompile".
I am using maven 2.2.1
I believe it is nothing to do with the scope of JUnit. Normally we set JUnit's scope to test (instead of provided) and everything is just fine.
src/test/java is compiled by Maven Compiler Plugin's testCompile goal. However, you don't need to explicitly run that goal. Please have a look in topics about Maven's Lifecycle. For example, if you run maven install, it is implicitly going through many phases (e.g. compile, compile test, generate resources etc), and many of them is bounded to a default plugin goal.
If you want to avoid test source from building, from Maven Compiler Plugin's usage page, compiler:testCompile will be skipped if you turn off testing by setting maven.test.skip=true
So, if your unit tests are not yet ready, just build with Maven, with -Dmaven.test.skip=true parameter.
Just to add, this is absolutely not a good practice to assume "unit test failing" being normal during development.
Just use the skip parameter for the maven-surefire-plugin which skip tests as well as compiling the test.
The pom.xml had defined "sourceDirectory" incorrectly. Removing it fixed the issue
Instead of command "maven clean compile" , use "mvn -B -Dmaven.test.skip=true clean compile". This parameter skips test.

Jacoco and Arquillian in a multi module Maven project

I am following this article: http://www.softwarepassion.com/it-coverage-with-arquillian-jacoco-extension/ to get test coverage for arquillian integration tests. My project is a multi module though and I don't know where to put the plug in and dependencies. Is it in the top pom, the artifact-making module or in the integration test module?
Thank you
To some extent it depends on the details of your Maven setup, which aren't in your question. Here is some general advice.
1) Where should you put the arquillian-jacoco and jacoco dependencies?
These dependencies should probably go wherever the rest of your Arquillian dependencies are. My understanding is that it is simply having these dependencies that triggers Arquillian to use JaCoCo, not the plugin declaration; even if these dependencies are in a parent of the POM with the actual Arquillian tests, the Arquillian test classes should still be instrumented. You wouldn't put these dependencies in a sibling module to the module with the tests though as they need to be inherited by the integration test module (unless this sibling module has been declared as a dependency of the test module of course).
2) Where should you put the JaCoCo plugin declaration?
As noted above, you may not even need this declaration, depending on what you are trying to achieve. If you want to generate a report, rather than just the jacoco.exec files, then you will need to declare the plugin and an execution with the report goal. You may also want to declare the plugin with the prepare-agent goal if you have other tests that you wish to be instrumented with JaCoCo, such as unit tests.
If you are going to declare the plugin, it can be treated the same way as any other Maven plugin. If you want to run JaCoCo across multiple modules by default you could choose to put the plugin declaration in your parent POM within the regular 'plugins' tag and have it inherited by all child modules, or you may wish to put it in the parent POM within the 'pluginManagement' element so the configuration can be inherited (see http://maven.apache.org/pom.html#Plugin_Management). Alternatively, if you only want to run Arquillian tests in your integration test module, you could also simply declare the plugin in this module's POM (given that you want a report, and without the prepare-agent goal if you're only instrumenting Arquillian tests).
Hope that helps!

How can i run maven tests against a previous deployed artifact of the same artifact?

I have an artifact abc which has some tests. I have different versions of abc within my repository. I now want to be able to run the latest tests against the 'old build' of the project.
I tried to add the artifact itself to the test dependencies but this (of course) results in a cyclic reference error of the maven reactor when building the tests via:
mvn compiler:testCompile
mvn surefire:test
Is there any smart way to run tests against a previous old build/artifact?
Must i create a new pom.xml in which i define the solo test execution?
Or should i add a postfix to my current artifact when executing the tests? (This would avoid a cyclic reference error)
Separate the tests out into a separate module/project that depends on the classes it tests. Then create separate profiles where you change the dependency to be on older releases.
The problem I foresee with what you're trying to do is that the package phase comes after the test phase of the maven lifecycle. Which to me implies that maven runs unit tests against the compiled classes and not the physical jar file (generated in the package phase). You'll therefore have to replace the contents of the projects /target/classes folder with the classes in the "older" jar.

maven junit pom.xml

i have a following problem.
I'd like ti test my JSF Application with JSFUnit.But JSFUnit supports inly junit3 (all our unit tests run with JUnit4).
Is it possible to include in pom.xml two junit dependencies (junit4 and junit3) with e.g. different scopes?
Please help and thanx in advance
If you separate the project into two submodules, one which needs JUnit3 and the other which needs JUnit4, you can specify the test dependencies separately in the child pom.
As Péter said, you should split your project in separate modules. In cases like this I've also seen the use of dedicated test modules turn out good results.
This way the JUnit4 test dependency you have in foo-web is not visible to the tests running from foo-web-jsf-tests.