Modify ↓

Opened 8 years ago

Last modified 2 weeks ago

#17012 new defect

JMockit : Cannot execute JUnit test MultipolygonTest from Eclipse

Reported by: GerdP Owned by: team
Priority: normal Milestone:
Component: Unit tests Version:
Keywords: eclipse jmockit Cc: ris

Description

When I try to execute MultipolygonTestTest in Eclipse I see the dump below. What do I have to do to make this work again?

MultipolygonTestTest
org.openstreetmap.josm.data.validation.tests.MultipolygonTestTest
testTicket10469(org.openstreetmap.josm.data.validation.tests.MultipolygonTestTest)
java.lang.ExceptionInInitializerError
	at org.openstreetmap.josm.testutils.JOSMTestRules.before(JOSMTestRules.java:543)
	at org.openstreetmap.josm.testutils.JOSMTestRules$CreateJosmEnvironment.evaluate(JOSMTestRules.java:640)
	at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalStateException: JMockit didn't get initialized; please check the -javaagent JVM initialization parameter was used
	at mockit.internal.startup.Startup.verifyInitialization(Startup.java:91)
	at mockit.MockUp.<clinit>(MockUp.java:56)

	... 19 more

Attachments (0)

Change History (11)

comment:1 by Don-vip, 8 years ago

Cc: ris added
Keywords: eclipse jmockit added

It's very cumbersome right now because JMockit requires adding VM argument -javaagent:<your directory>/josm/core/test/lib/jmockit-1.43.jar on the command line

comment:2 by Don-vip, 8 years ago

@ris can we make a change so this is only needed for tests really using JMockit? It shouldn't be needed for 90% of tests, like MultipolygonTestTest in this case.

comment:3 by michael2402, 8 years ago

We should add a new test rules setting for this - but this will only work on a per-class basis.

When we switch to Junit Jupiter, we can write an extension and add the @ExtendWith() only to the test methods that use it.

in reply to:  1 comment:4 by GerdP, 8 years ago

Replying to Don-vip:

It's very cumbersome right now because JMockit requires adding VM argument -javaagent:<your directory>/josm/core/test/lib/jmockit-1.43.jar on the command line

OK, that did the trick. Just a hint: This is not needed to run e.g. RelationCheckerTest.

comment:5 by ris, 8 years ago

can we make a change so this is only needed for tests really using JMockit?

That's a very good question - the answer is I don't know. I don't know a lot about eclipse and how it runs individual tests...

comment:6 by Don-vip, 8 years ago

This is not really specific to Eclipse, you may have the issue with all IDEs I think, as I don't see how they could guess we need to add the JMockit agent. How do you run unit tests while developing them?

comment:7 by ris, 8 years ago

I'm a text-editor-and-a-terminal kinda guy. If I want to run a subset or just a particular test I really just change the glob pattern in <batchtest><fileset> ... and re-run.

comment:8 by michael2402, 8 years ago

In #8269 there is a gradle build script.

Once we switch to gradle, you can simply use --tests=..pattern..

For Eclipse, you can use a new JVM configuration for your project. You can use the same Java home directory but you add the agent arguments to the default arguments. Since the tests in your project are then run using that JVM, you always have the agent even if you just re-run a single test.

comment:9 by gaben, 2 weeks ago

@GerdP: Is it still an issue? I'm using IntelliJ and the test compiles fine here.

Last edited 2 weeks ago by gaben (previous) (diff)

comment:10 by GerdP, 2 weeks ago

I just tried this: Remove the existing "run configuration" for MultipolygonTesttest and then try to "Run As-> JUnit Test".
This fails with a popup saying "Variable com.ginsberg does not accept arguments"
After that there is a newly genarated run configuration with these VM arguments:

-ea

                -Djava.locale.providers=SPI,CLDR
                -javaagent:${com.ginsberg:junit5-system-exit:jar}
                -javaagent:${org.jmockit:jmockit:jar}
                --add-opens java.base/java.io=ALL-UNNAMED
                --add-opens java.base/java.lang=ALL-UNNAMED
                --add-opens java.base/java.nio=ALL-UNNAMED
                --add-opens java.base/java.text=ALL-UNNAMED
                --add-opens java.base/java.util=ALL-UNNAMED
                --add-opens java.base/jdk.internal.loader=ALL-UNNAMED
                --add-opens java.desktop/java.awt=ALL-UNNAMED
                --add-opens java.prefs/java.util.prefs=ALL-UNNAMED
-Dglass.platform=Monocle
-Djava.awt.headless=true
-Djosm.home=C:\josm\core/test/config/josm.home
-Djosm.test.data=C:\josm\core/test/data
-Dmonocle.platform=Headless
-Dprism.order=sw

Whenever this happens (always?) I run the test on the command line, which is much more time consuming but works fine otherwise.
My Eclipse installation is

Version: 2025-09 (4.37.0)
Build id: 20250905-1456

I now try to update Eclipse (failed a few times in the past)

comment:11 by GerdP, 2 weeks ago

After updating Eclipe to

Version: 2026-09 (4.41.0)
Build id: 20260903-0720

I repeated the steps. Still doesn't work but with a different error:

Error occurred during initialization of VM
agent library failed to init: instrument
Error opening zip file or JAR manifest missing : 

The generated VM arguments are now

-ea

                -Djava.locale.providers=SPI,CLDR
                -javaagent:
                -javaagent:
                --add-opens java.base/java.io=ALL-UNNAMED
                --add-opens java.base/java.lang=ALL-UNNAMED
                --add-opens java.base/java.nio=ALL-UNNAMED
                --add-opens java.base/java.text=ALL-UNNAMED
                --add-opens java.base/java.util=ALL-UNNAMED
                --add-opens java.base/jdk.internal.loader=ALL-UNNAMED
                --add-opens java.desktop/java.awt=ALL-UNNAMED
                --add-opens java.prefs/java.util.prefs=ALL-UNNAMED
-Dglass.platform=Monocle
-Djava.awt.headless=true
-Djosm.home=C:\josm\core/test/config/josm.home
-Djosm.test.data=C:\josm\core/test/data
-Dmonocle.platform=Headless
-Dprism.order=sw

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user.
Next status will be 'needinfo'. The owner will be changed from team to GerdP.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.
The owner will be changed from team to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.