custom classpath / modifying classpath in a junit5 test - junit5

Is it possible do modify/filter the classpath of a test?
Reason: Our SWT GUI tests are including all platform SWT libs and we need to exclude the wrong libs. In junit4 it was possible with a custom Runner (#RunWith).
With junit5 is it possible to inject/modify a custom classpath with #ExtendWith or at phase #BeforeAll ?

Related

Karate Gatling - How to run Gatling tests using Maven uber jar [duplicate]

I am using karate 0.9.2 with gradle. My project requires to have all karate tests inside src/main/java. So I configured the gradle dependency as ‘compile’ instead of ‘testCompile’ and also modified the sourceSets to point to main instead of test. When I ran my runner class with above configuration I got empty test suite message.
build.gradle snippet:
compile 'com.intuit.karate:karate-junit4:0.9.3'
compile 'com.intuit.karate:karate-apache:0.9.3'
sourceSets {
test {
resources {
srcDir file('src/main/java')
exclude '**/*.java'
}
}
}
Additionally, I have is to run the karate tests from the deployable project jar. Please point me the resources I can refer to achieve the same.
Not something we directly support but teams have done this in Spring Boot etc. It should be possible, see if this thread helps: https://github.com/intuit/karate/issues/520
Also you may not need JUnit also: https://github.com/intuit/karate/issues/427
And see the sample project in this ticket as an example: https://github.com/intuit/karate/issues/529
EDIT - in 1.0 onwards we hope that class-loading from spring-boot JAR files is more reliable: https://github.com/intuit/karate/issues/751

setting classpath for gradle task / runconfig in intellij

I'm running unit tests in Intellij 14.1.2 with the Gradle plugin. I have external config and test data that is in environment specific in a set of directories (directory for each env). I want to load the config and data via the classpath.
In Eclipse I'd just add the env specific path to the run-config and save the config as:
'Test-XYZ-UAT1'
for example.
In intellij, it seems my application config classpath is tied to my 'module' classpath:
https://www.jetbrains.com/help/idea/2016.3/run-debug-configuration-application.html
how to add directory to classpath in an application run profile in intellij idea?
..which is bad enough but for the Gradle run configs I don't even have the option to add the module classpath.
Run/Debug Configurations window has no:
'Use classpath of mod...'
section.
Question:
How can I set the classpath of the run config when running a Gradle Task within Intellij ?
..and if someone could tell me how to get application run config specific classpaths setup that would be even better.
(please tell me I'm missing something ingenius about Intellij..)
Based on quite a bit of research and trial and error, here is the solution that works for my Kotlin based Spring Boot project.
Background:
My Spring Boot project run configuration is configured to use Run Gradle task in place of the standard IDEA build as its Before launch configuration (see screen shot below).
My Spring Boot project uses src/main/resources/application.properties for JPA and logging properties.
gradle build uses the following output directories for the build. These are the default gradle build output directories for a Kotlin project.
build/classes/kotlin/main for the main class files.
build/classes/kotlin/test for the test class files.
build/resources/main for the main resource files. This is where application.properties is copied during a build.
When I attempted to run this project inside IDEA using the run configuration above, it would fail during Spring Boot start up because it could not find application.properties inside the classpath. When I inspected the classpath used during application startup, build/resources/main was missing.
My Solution
Use the information from: Gradle Goodness: Delegate Build And Run Actions To Gradle In IntelliJ IDEA to delegate IDEA build and execution to Gradle.
When IDEA is configured to delegate build and execution to Gradle, the main and test modules should be configured as follows: On the Paths tab, select Inherit project compile output path.

Use findbug's surpresswarning annotations from eclipse in hudson

I got a hudson job which analyses the sources with findbugs. I'm currently using filters to surpress the warings but it would be better if I could surpress them directly in code.
I've seen that there is a findbugs plugin to analyse the code in eclipse and add annotations there. Do I need anything to make the annotations from eclipse work in hudson? The thing is I dont want to add FindBugs to the classpath of the projects... Is the eclipse plugin enouth and if yes what do I have to do to make it work in the hudson job.
The FindBugs annotation for suppressing false positives is #edu.umd.cs.findbugs.annotations.SuppressFBWarnings.
In order to use the FindBugs annotations, the following two JAR files must be on the Classpath:
annotations-x.x.x.jar (replace 'x' with FindBugs version number)
jsr305.jar
These files must be on the classpath of the process that performs the FindBugs analysis. They do not need to be on the classpath in production. In other words, you must add them to the Eclipse classpath and probably also in your build scripts (so that analysis works in Hudson). However, you do not need to deploy the files into production.
If you don't want to modify the projects' classpath, then it will probably not work in Hudson. It should work in Eclipse, although you will be required to put them in some global classpath, which is kinda dirty.

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.

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!