cancel
Showing results for 
Search instead for 
Did you mean: 

MVN amp project JUNIT test fails with init error

mxc
Confirmed Champ
Confirmed Champ
Hi there,

I have used the DemoComponenet test as a basis to build a JUNIT test. However when I run the test I get:


java.lang.RuntimeException: Unable to create instanceof class org.springframework.test.context.junit4.SpringJUnit4ClassRunner
   at com.tradeshift.test.remote.internal.Utils.createRunner(Utils.java:77)
   at com.tradeshift.test.remote.RemoteTestRunner.<init>(RemoteTestRunner.java:44)

…..
Caused by: java.lang.reflect.InvocationTargetException: null
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)





I am not sure where the unit test picks up the spring application context because it does not appear to be anywhere in the project. Although the DemoComponent test runs fine without it. There appears to be no test specific resources in the project created by the mvn plugin.

@RunWith(RemoteTestRunner.class)
@Remote(runnerClass = SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:alfresco/application-context.xml")


Any help appreciated.
2 REPLIES 2

jpotts
World-Class Innovator
World-Class Innovator
Here is a project with a working unit test I created recently:
https://github.com/jpotts/share-site-space-templates

It was bootstrapped with the Alfresco Maven SDK.

Maybe comparing its structure and unit test with yours will be helpful.

One thing I noticed is that the application-context.xml gets created automatically when you run mvn integration-test. But, as you noted, my unit test runs fine without it when running mvn install, so that's probably not your problem.

Jeff

mxc
Confirmed Champ
Confirmed Champ
Thanls for the reply Jeff. I had a look at your code and couldn't get any clue as to why the test does not run. I changed the annotations at the top of the class from

@RunWith(RemoteTestRunner.class)
@Remote(runnerClass = SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:alfresco/application-context.xml")


to

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:alfresco/application-context.xml")


At lest the tests are running now. I will have to find out about the RemoteTestRunner annotation and see what its all about. Odd that it runs without any issue with the DemoComponent test.