Hello everybody
I have two projects, one is A and one is A_Test. And i try to run JUnit Test case from project A_Test to test some functionalities of A. Here is a portion of code
Project A
public CalendarEventRequest(){
this.organizer = **Ivy.var().get("xabs_calendarEvent_organizer").toString();**
Calendar c = new GregorianCalendar(Ivy.session().getContentLocale());
this.timezone= c.getTimeZone();
}
Test case
@Test
public void testCreateCalendarEvent002() throws Exception {
CalendarEventRequest request = new CalendarEventRequest();
CalendarEventResult result = CalendarUtil.createCalendarEvent(request);
assertNotNull(result);
}
And JUnit threw this exception:
ch.ivyteam.ivy.environment.EnvironmentNotAvailableException: Access to ivy environment outside a process request thread is not possible.
Current thread: Thread[main,5,main]
at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:455)
at ch.ivyteam.ivy.environment.Ivy.var(Ivy.java:272)
at ch.soreco.customers.xabs.bean.CalendarEventRequest.<init>(CalendarEventRequest.java:26)
at ch.soreco.customers.xabs.bean.CalendarUtilTest.createRequestForOneDay(CalendarUtilTest.java:75)
at ch.soreco.customers.xabs.bean.CalendarUtilTest.testCreateCalendarEvent002(CalendarUtilTest.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
anyone can help me?
asked
07.04.2014 at 09:34
trungdv
(suspended)
accept rate:
52%
My Co-worker changed the current unittesting code to a more convenient one. He simply mocks the the ivy engine with Jmockit.
so we can use the mock in the unittests without starting any ivy relevant stuff.
The unit test looks like: