2012-11-30 69 views
0

我正在使用JUnit進行Web服務(Springs)的單元測試。運行JUnit測試用例時加載應用程序競爭錯誤失敗

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration({"classpath:WSexample/config/service/WSexample-service.xml‌"}) 

和測試文件位於WSexample/test/find/controller位置

我使用上面的代碼來加載一個XML文件。它正在拋出無法加載應用程序上下文錯誤。

java.lang.IllegalStateException:無法在org.springframework.test.context.TestContext.getApplicationContext(TestContext.j ava:308)上加載ApplicationContext,位於org.springframework.test.context.support.DependencyInjectionTestExecutionListene r。在org.springframework.test.context.TestContextManager.prepareTestInstance中測試org.springframework.test.context.support.DependencyInjectionTestExecutionListene中的injectDependencies(DependencyInjectionTestExecutionListener.java:109)r.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)(TestCont extManager.java: 321)

任何人都可以幫我解決這個問題。

在此先感謝。

+0

請包括實際錯誤 –

+0

再次,不要使用評論來更新問題。更新問題。 –

回答

0

您可能需要使用SpringJunit4ClassRunnerContextConfiguration加載您的上下文文件。

退房this後。

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations={"classpath:myContext.xml"}) 
+0

我用過這個,但是它的賦值失敗加載applicationcontext錯誤 我的文件不在WEB-INF文件夾中。它位於不同的文件夾中,其名稱爲「WSexample-service.xml」 – user1853173

+0

如果未查看測試的相關部分以及要加載的上下文文件的路徑,則很難提供幫助。問題是,你是否在'ContextConfiguration'中放置了合適的文件名和路徑? –

+0

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({「classpath:WSexample/config/service/WSexample-service.xml」}) 並且測試文件位於WSexample/test/find/controller位置 – user1853173