论坛首页 综合技术论坛

请教 Struts2.0 中怎样使用 StrutsTestCase 进行测试?

浏览 7178 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-05-20  
参考了本论坛中的代码
import static org.junit.Assert.*;

import org.junit.Before;
import org.apache.struts2.StrutsTestCase;
import com.opensymphony.xwork2.config.ConfigurationProvider;

public class BaseStruts2ActionTest extends StrutsTestCase {

	@Before
	public void setUp() throws Exception {
		super.setUp();
		/**
		 * 关键是调用这个方法,使用在StrutsTestCase里被装入的所有provider来初始化XWorkTestCase下的
		 * ConfigurationManager configurationManager; Configuration
		 * configuration; Container container; ActionProxyFactory
		 * actionProxyFactory;
		 * 如果不调用这个方法重新构建configurationManager,将抛出java.lang.UnsupportedOperationException异常
		 * 
		 */
		this.loadConfigurationProviders((ConfigurationProvider[]) this.configurationManager
						.getConfigurationProviders().toArray(
								new ConfigurationProvider[0]));
	}

	public void testA() {

	}

}




运行时报错
2008-05-20 13:17:52,806 FATAL (org.apache.struts2.spring.StrutsSpringObjectFactory:67) - ********** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION **********
Looks like the Spring listener was not configured for your web app!
Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.
You might need to add the following to web.xml:
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


要正常使用StrutsTestCase需要进行怎样的配置  这里说的web.xml  应该放在那里?
我使用的工具是 myeclipse  project中已有webapplication

---------------------------------
以前没写过测试代码,问的问题可能不算是问题.
   发表时间:2008-05-20  
问题已经解决,多了个 struts2-spring-plugin-2.0.9.jar 就会出现此错误. 
0 请登录后投票
   发表时间:2008-07-10  
agu 写道
问题已经解决,多了个 struts2-spring-plugin-2.0.9.jar 就会出现此错误. 

那如果是对ssh项目进行测试,不就无从下手了,天哪!
0 请登录后投票
   发表时间:2008-09-12  
这位朋友请教一个问题:为什么我的

this.loadConfigurationProviders((ConfigurationProvider[]) this.configurationManager  
                        .getConfigurationProviders()
.toArray(new ConfigurationProvider[0]));
会提示空指针异常呢?
是在getConfigurationProviders()提示空指针异常的

0 请登录后投票
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics