春季测试:无法加载ApplicationContext

时间:2018-10-22 15:00:18

标签: java spring testng spring-test

我无法加载applicationcontext。扩展AbstractTestNGSpringContextTests的类,它是applicationcontextaware。任何帮助,这里缺少什么?这是一个简单的弹簧测试文件。我正在使用弹簧靴。我是否需要对配置进行任何设置才能获取applicationcontext。

// remove our action temporarily 
remove_action('pre_get_posts','exclude_pages_from_search');

$hidePages = new WP_Query( array ( ... //your query
$hidePageIds = implode( ',', $hidePages->posts );

// add the action again
add_action('pre_get_posts','exclude_pages_from_search'); 

if ... //rest of your function

这里是Test类

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
    at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)

0 个答案:

没有答案