InitilizationError when JunitTest with Maven

I try to run Junit-Test with Maven3, but always get initinizationError (some test class here) when running a test that has JUnit-Annotations (all other tests work fine). When I run tests in Eclipse, everything is fine. But running the tests with maven will be broken. My test project is packaged as an eclipse plugin. I am using maven-osgi-test-plugin.

My test class is annotated:

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="classpath:applicationContext.xml") @TransactionConfiguration public class ArtifactManagerTest extends AbstractTransactionalJUnit4SpringContextTests {... 

For each test class annotated with @ContextConfiguration, there is a classname-test.xml file. In this configuration file, I import applicationContext-Test.xml using "classpath:"

My pom.xml test plugin looks like this:

 <groupId>foo.bar</groupId> <artifactId>company.xyz</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>eclipse-test-plugin</packaging> <build> <plugins> <plugin> <groupId>org.sonatype.tycho</groupId> <artifactId>maven-osgi-test-plugin</artifactId> <configuration> <useUIHarness>true</useUIHarness> <testSuite>company.xyz.test</testSuite> <testClass>company.xyz.AllTests</testClass> <argLine>-Xmx512m</argLine> <bundleStartLevel> <bundle> <id>org.eclipse.equinox.ds</id> <level>1</level> <autoStart>true</autoStart> </bundle> </bundleStartLevel> </configuration> <inherited>true</inherited> </plugin> </plugins> </build> 

The failure output is as follows:

  initializationError (company.xyz.ArtifactManagerTest) Time elapsed: 0 sec (ParentRunner.java:66)
         at org.junit.runners.BlockJUnit4ClassRunner. (BlockJUnit4ClassRunner.java:59)
         at org.springframework.test.context.junit4.SpringJUnit4ClassRunner. (SpringJUnit4ClassRunner.java:104)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance (Constructor.java∗13)
         at org.junit.internal.builders.AnnotatedBuilder.buildRunner (AnnotatedBuilder.java:31)
         at org.junit.internal.builders.AnnotatedBuilder.runnerForClass (AnnotatedBuilder.java:24)
         at org.junit.runners.model.RunnerBuilder.safeRunnerForClass (RunnerBuilder.java:57)
         at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass (AllDefaultPossibilitiesBuilder.java
 : 29)
         at org.junit.runners.model.RunnerBuilder.safeRunnerForClass (RunnerBuilder.java:57)
         at org.junit.runners.model.RunnerBuilder.runners (RunnerBuilder.java:93)
         at org.junit.runners.model.RunnerBuilder.runners (RunnerBuilder.java:84)
         at org.junit.runners.Suite. (Suite.java:101)
         at org.junit.runners.Suite. (Suite.java:67)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance (Constructor.java∗13)
         at org.junit.internal.builders.AnnotatedBuilder.buildRunner (AnnotatedBuilder.java:35)
         at org.junit.internal.builders.AnnotatedBuilder.runnerForClass (AnnotatedBuilder.java:24)
         at org.junit.runners.model.RunnerBuilder.safeRunnerForClass (RunnerBuilder.java:57)
         at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass (AllDefaultPossibilitiesBuilder.java
 : 29)
         at org.junit.runners.model.RunnerBuilder.safeRunnerForClass (RunnerBuilder.java:57)
         at org.junit.runners.model.RunnerBuilder.runners (RunnerBuilder.java:93)
         at org.junit.runners.model.RunnerBuilder.runners (RunnerBuilder.java:84)
         at org.junit.runners.Suite. (Suite.java:101)
         at org.junit.runners.Suite. (Suite.java:67)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance (Constructor.java∗13)
         at org.junit.internal.builders.AnnotatedBuilder.buildRunner (AnnotatedBuilder.java:35)
         at org.junit.internal.builders.AnnotatedBuilder.runnerForClass (AnnotatedBuilder.java:24)
         at org.junit.runners.model.RunnerBuilder.safeRunnerForClass (RunnerBuilder.java:57)
         at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass (AllDefaultPossibilitiesBuilder.java
 : 29)
         at org.junit.runners.model.RunnerBuilder.safeRunnerForClass (RunnerBuilder.java:57)
         at org.junit.internal.requests.ClassRequest.getRunner (ClassRequest.java:24)
         at org.apache.maven.surefire.junit4.JUnit4TestSet. (JUnit4TestSet.java:45)
         at org.apache.maven.surefire.junit4.JUnit4DirectoryTestSuite.createTestSet (JUnit4DirectoryTestSuite.java:56)
         at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.locateTestSets (AbstractDirectoryTestSuite.java:96)
         at org.apache.maven.surefire.Surefire.createSuiteFromDefinition (Surefire.java:209)
         at org.apache.maven.surefire.Surefire.run (Surefire.java:156)
         at org.codehaus.tycho.surefire.osgibooter.OsgiSurefireBooter.run (OsgiSurefireBooter.java:75)
         at org.codehaus.tycho.surefire.osgibooter.AbstractUITestApplication $ 1.run (AbstractUITestApplication.java:25)
         at org.eclipse.swt.widgets.RunnableLock.run (RunnableLock.java:35)
         at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages (Synchronizer.java:134)
         at org.eclipse.swt.widgets.Display.runAsyncMessages (Display.java:4041)
         at org.eclipse.swt.widgets.Display.readAndDispatch (Display.java:3660)
         at org.eclipse.ui.internal.Workbench.runEventLoop (Workbench.java:2640)
         at org.eclipse.ui.internal.Workbench.runUI (Workbench.java:2604)
         at org.eclipse.ui.internal.Workbench.access $ 4 (Workbench.java:2438)
         at org.eclipse.ui.internal.Workbench $ 7.run (Workbench.java:671)
         at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java data32)
         at org.eclipse.ui.internal.Workbench.createAndRunWorkbench (Workbench.java:664)
         at org.eclipse.ui.PlatformUI.createAndRunWorkbench (PlatformUI.java:149)
         at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
         at org.codehaus.tycho.surefire.osgibooter.UITestApplication.runApplication (UITestApplication.java:21)
         at org.codehaus.tycho.surefire.osgibooter.AbstractUITestApplication.run (AbstractUITestApplication.java:109)
         at org.codehaus.tycho.surefire.osgibooter.UITestApplication.start (UITestApplication.java:27)
         at org.eclipse.equinox.internal.app.EclipseAppHandle.run (EclipseAppHandle.java:196)
         at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication (EclipseAppLauncher.java:110)
         at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start (EclipseAppLauncher.java:79)
         at org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.javahaps69)
         at org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.java:179)
         at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke (Method.java∗97)
         at org.eclipse.equinox.launcher.Main.invokeFramework (Main.java:619)
         at org.eclipse.equinox.launcher.Main.basicRun (Main.java∗74)
         at org.eclipse.equinox.launcher.Main.run (Main.java:1407)
         at org.eclipse.equinox.launcher.Main.main (Main.java:1383)

In surefire reports, I see that java.class.path is installed in my local maven repository at 'org.eclipse.equinox.launcher-1.1.0.v20100507.jar'

It seems that the classpath is not set correctly, so maven cannot find applicationContext.xml ? But how to do it right?

+4
source share
1 answer

Please make sure that the @BeforeClass and @AfterClass are "public static void" and no arguments in your test class of the ArtifactManagerTest class.

Edit: InitializationError is raised when @BeforeClass and @AfterClass , so @BeforeClass is not even executed.

If possible, use the following code for error information:

 Result r=new JUnitCore().run(ArtifactManagerTest.class); for(Failure f:r.getFailures()){ System.out.println(f); } 
+1
source

Source: https://habr.com/ru/post/1336937/


All Articles