Running tests via maven

Hi,

can I build and run the unit tests via maven? Not the maven expert, but I’d like to fix a bug in the Interactive Broker XML importer and would like to add a unit test. Basically just a precision bug when calculating fees in USD. Tried mvn test in portfolio-app but it produced an error.

Christian

3 Likes

Tests are also run during the Maven build. Also on Travis CI. From the command line, I am running mvn clean verify -Dtycho.disableP2Mirrors and it executes the tests.

What was the error?

I debugged further and I found out that it is a Java 10 error. If I go back to Java 1.8, the tests pass through. Just in case the error is below.

       [ERROR] Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:1.2.0:test (default-test) 
on project name.abuchen.portfolio.tests: An unexpected error occured while launching the test 
runtime (return code 134). See log /Users/chris/WorkArea/portfolio/name.abuchen.portfolio.tests/target/work/data/.metadata/.log for details. -> [Help 1]

The directory data/.metadata doesn’t exist in the given directory. It cannot launch the tests:

[INFO] Command line:
	[/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home/bin/java, -Dosgi.noShutdown=false, -Dosgi.os=macosx, -Dosgi.ws=cocoa, -Dosgi.arch=x86_64, -javaagent:/Users/chris/.m2/repository/org/jacoco/org.jacoco.agent/0.7.6.201602180812/org.jacoco.agent-0.7.6.201602180812-runtime.jar=destfile=/Users/chris/WorkArea/portfolio/portfolio-app/target/jacoco.exec, -Dosgi.clean=true, -jar, /Users/chris/.m2/repository/p2/osgi/bundle/org.eclipse.equinox.launcher/1.5.0.v20180512-1130/org.eclipse.equinox.launcher-1.5.0.v20180512-1130.jar, -debug, -consolelog, -data, /Users/chris/WorkArea/portfolio/name.abuchen.portfolio.tests/target/work/data, -install, /Users/chris/WorkArea/portfolio/name.abuchen.portfolio.tests/target/work, -configuration, /Users/chris/WorkArea/portfolio/name.abuchen.portfolio.tests/target/work/configuration, -application, org.eclipse.tycho.surefire.osgibooter.headlesstest, -testproperties, /Users/chris/WorkArea/portfolio/name.abuchen.portfolio.tests/target/surefire.properties]
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:510)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:522)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
	at org.jacoco.agent.rt.internal_14f7ee5.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:139)
	at org.jacoco.agent.rt.internal_14f7ee5.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:100)
	at org.jacoco.agent.rt.internal_14f7ee5.PreMain.createRuntime(PreMain.java:55)
	at org.jacoco.agent.rt.internal_14f7ee5.PreMain.premain(PreMain.java:47)
	... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
	at java.base/java.lang.Class.getField(Class.java:1958)
FATAL ERROR in native method: processing of -javaagent failed
	at org.jacoco.agent.rt.internal_14f7ee5.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:137)
	... 9 more

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Portfolio Performance 0.33.2-SNAPSHOT .............. SUCCESS [  0.501 s]
[INFO] name.abuchen.portfolio ............................. SUCCESS [ 49.485 s]
[INFO] name.abuchen.portfolio.tests ....................... FAILURE [ 56.131 s]
[INFO] name.abuchen.portfolio.ui .......................... SKIPPED
[INFO] name.abuchen.portfolio.ui.tests .................... SKIPPED
[INFO] name.abuchen.portfolio.bootstrap ................... SKIPPED
[INFO] name.abuchen.portfolio.feature ..................... SKIPPED
[INFO] portfolio.product 0.33.2-SNAPSHOT .................. SKIPPED
[INFO] ------------------------------------------------------------------------

Ok, I’ve setup in Eclipse, worked well so far, Pull request is here: https://github.com/buchen/portfolio/pull/1013

I

I haven’t played around with Java 10 yet. Looks like it is time…

Thanks for the PR, will have a look at it - hopefully in the next couple days.