Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369266

Summary: JUnit "eclipse-test-plugin" integration-test fails; unable to find test annotations
Product: z_Archived Reporter: Matthew O'Connor <thegreendragon>
Component: TychoAssignee: Jan Sievers <jan.sievers>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: arcadiy, cndhu17, cvgaviao, dave.henderson, d_a_carver, igor, jan.sievers, lonniev, malaperle, nigelipse, ruediger.herrmann, sewe, t-oberlies, tnaroska
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 386481    
Bug Blocks:    
Attachments:
Description Flags
Example project and integration test demonstrating example
none
Log of test error none

Description Matthew O'Connor CLA 2012-01-20 13:04:31 EST
Created attachment 209844 [details]
Example project and integration test demonstrating example

I've created a simple Tycho POM project with an "eclipse-plugin" and "eclipse-test-plugin". When I run "mvn integration-test", it fails with the attached error log.

If I change the Tycho version back to 0.13.0, the test passes.
Comment 1 Matthew O'Connor CLA 2012-01-20 13:05:42 EST
Created attachment 209845 [details]
Log of test error
Comment 2 Jan Sievers CLA 2012-01-25 07:02:17 EST
seems related to Import-Package on org.junit.

If I change

Import-Package: org.junit;version="[4,5)"

to

Require-Bundle: org.junit;bundle-version="4.8.1"

the test works fine.

Alternatively, adding an Import-Package for org.junit.runner also works around the problem.

It seems that surefire (at least in the new version 2.10 we use now) implicitly assumes that org.junit.runner.RunWith can be loaded by the test classloader.

See [1], line 46. This is not a problem in non-OSGi environemtns but with OSGi classloaders and Import-Package, whether a class can be loaded or not is controlled down to the package level...



[1] http://svn.apache.org/viewvc/maven/surefire/tags/surefire-2.10/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4TestChecker.java?view=markup
Comment 3 Jan Sievers CLA 2012-01-26 03:54:51 EST
For now I tend to treat this as a surefire bug. I think that surefire should gracefully handle the case where the RunWith class can't be loaded by the test classloader.

Will probably open a bug on surefire and try to provide a patch there.
Comment 4 Matthew O'Connor CLA 2012-01-26 15:04:18 EST
Thanks for looking at this.

Changing from "Import-Package" to "Require-Bundle" works around this issue for me for now.

I'll leave this issue open (or to you) as a pointer/note for the Surefire issue.
Comment 5 Jan Sievers CLA 2012-01-30 04:48:05 EST
opened surefire bug http://jira.codehaus.org/browse/SUREFIRE-825 with patch attached.
Comment 6 Jan Sievers CLA 2012-02-28 08:50:23 EST
note to self: watch out for possible regression https://jira.codehaus.org/browse/SUREFIRE-844 when adopting surefire 2.13
Comment 7 Tobias Oberlies CLA 2012-04-23 09:05:17 EDT
There is an easy workaround - reducing priority.
Comment 8 David Carver CLA 2012-06-25 17:32:19 EDT
*** Bug 383490 has been marked as a duplicate of this bug. ***
Comment 9 Jan Sievers CLA 2012-06-26 03:05:29 EDT
(In reply to comment #5)
> opened surefire bug http://jira.codehaus.org/browse/SUREFIRE-825 with patch
> attached.

patch accepted for surefire 2.13 but not released yet.
Comment 10 Jan Sievers CLA 2012-08-02 05:22:33 EDT
maven surefire 2.12.1 was released which includes the fix for https://jira.codehaus.org/browse/SUREFIRE-844.
Comment 11 Jan Sievers CLA 2012-08-02 07:50:22 EDT
(In reply to comment #10)
> maven surefire 2.12.1 was released which includes the fix for
> https://jira.codehaus.org/browse/SUREFIRE-844.
sorry, I meant to say http://jira.codehaus.org/browse/SUREFIRE-825  of course
Comment 12 Tobias Oberlies CLA 2013-08-30 11:13:09 EDT
To clarify the status of this issue:
* There is a workaround (see comment #2)
* The issue is not resolved because we haven't integrated the fixed surefire version yet (see bug 386481)
Comment 13 Jan Sievers CLA 2014-03-31 03:26:57 EDT
*** Bug 431593 has been marked as a duplicate of this bug. ***
Comment 14 Jan Sievers CLA 2014-08-14 09:09:12 EDT
https://git.eclipse.org/r/#/c/31274/1
Comment 16 Lonnie VanZandt CLA 2015-02-03 23:57:31 EST
Can a Tycho or Maven Surefire site add some user documentation on how to configure the MANIFEST.MF, pom.xml, and maven-surefire-plugin for projects that consist of multiple eclipse-project and eclipse-test-projects such that @RunWith annotated test cases are executable during command-line maven sessions?

I am attempting to track down why a project's OSGi session for surefire junit testing fails to find the expected Parameterized RunWith class and silently chooses the default BlockJUnit4ClassRunner class instead. That leads to this exception:

java.lang.Exception: Test class should have exactly one public zero-argument constructor
	at org.junit.runners.BlockJUnit4ClassRunner.validateZeroArgConstructor(BlockJUnit4ClassRunner.java:144)
	at org.junit.runners.BlockJUnit4ClassRunner.validateConstructor(BlockJUnit4ClassRunner.java:121)

The test plugin properly runs the JUnit test suite from within Eclipse. Documentation on how to use the newer Junit4 annotations within surefire would be helpful.

This relates, I believe, to the resolved issue here. I suspect that some explicit statement of Require-Bundle or Import-Package for transitive dependencies is needed within the MANIFEST.MF.
Comment 17 Tobias Oberlies CLA 2015-02-05 08:14:35 EST
(In reply to comment #16)
> The test plugin properly runs the JUnit test suite from within Eclipse.
"JUnit Test" or "JUnit Plug-in Test"?

> Documentation on how to use the newer Junit4 annotations within surefire would
> be helpful.
There should be nothing special to consider. If it doesn't work, then you may have found an unknown bug/limitation. If you can reproduce this issue in a minimal, standalone project, please open a new issue.
Comment 18 Lonnie VanZandt CLA 2015-02-08 20:24:14 EST
Within Eclipse, it is the Run As Junit Test variation that works. (I haven't looked into what it takes to get an eclipse-test-plugin that is an OSGi fragment bundle to work within Eclipse. Running as a Junit Test is enough for developer purposes.)
Comment 19 Jan Sievers CLA 2015-02-09 04:25:52 EST
(In reply to Lonnie VanZandt from comment #18)
> Within Eclipse, it is the Run As Junit Test variation that works. (I haven't
> looked into what it takes to get an eclipse-test-plugin that is an OSGi
> fragment bundle to work within Eclipse. Running as a Junit Test is enough
> for developer purposes.)

this discussion is out of scope for this bug.

If you think you found a new bug, open a separate ticket with sample project and steps to reproduce.
Comment 20 Tobias Oberlies CLA 2015-02-11 09:36:03 EST
(In reply to comment #18)
> Within Eclipse, it is the Run As Junit Test variation that works. (I haven't
> looked into what it takes to get an eclipse-test-plugin that is an OSGi fragment
> bundle to work within Eclipse. Running as a Junit Test is enough for developer
> purposes.)
So you are not using OSGi when running the tests in Eclipse, and using OSGi when running the tests in Tycho. So your OSGi configuration is incorrect.

Please use the regular support channels (e.g. tycho-user@eclipse.org) to get help if needed. Or if you think you have found a bug, do this as proposed in comment #19 and comment #17.
Comment 21 sindhu gururaj CLA 2015-06-03 03:37:51 EDT
am running tests using tycho 0.22.0 i get the following error
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:0.22.0:test (default-test) on project com.xxxxx.abc.datamodel.test: Execution default-test of goal org.eclipse.tycho:tycho-surefire-plugin:0.22.0:test failed. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:0.22.0:test (default-test) on project com.xxxxx.abc.datamodel: Execution default-test of goal org.eclipse.tycho:tycho-surefire-plugin:0.22.0:test failed.
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-test of goal org.eclipse.tycho:tycho-surefire-plugin:0.22.0:test failed.
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
	... 19 more
Caused by: java.lang.NullPointerException
	at org.apache.maven.plugin.surefire.util.ScannerUtil.processIncludesExcludes(ScannerUtil.java:68)
	at org.apache.maven.plugin.surefire.util.DirectoryScanner.scan(DirectoryScanner.java:76)
	at org.eclipse.tycho.surefire.TestMojo.scanForTests(TestMojo.java:892)
	at org.eclipse.tycho.surefire.TestMojo.createSurefireProperties(TestMojo.java:847)
	at org.eclipse.tycho.surefire.TestMojo.createEclipseInstallation(TestMojo.java:740)
	at org.eclipse.tycho.surefire.TestMojo.execute(TestMojo.java:621)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
	... 20 more
Comment 22 Jan Sievers CLA 2015-06-03 04:04:23 EDT
(In reply to sindhu gururaj from comment #21)
> am running tests using tycho 0.22.0 i get the following error

this doesn't belong here. please open a new bug with steps to reproduce.