51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2120|回复: 1
打印 上一主题 下一主题

[讨论] spring的WEB测试,怎么搭建环境??求助

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2008-9-12 09:51:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
小弟对WebService进行测试

环境是spring2.5 + JUnit 4  spring提供了一个包,spring-test

1.建立基本测试类 BaseServiceTest extends AbstractTransactionalSpringContextTests

2.重载 AbstractTransactionalSpringContextTests 的方法以读入spring等的配置文件

@Override
        protected String[] getConfigLocations() {
                String root = "file:d:/work/testook/web/WEB-INF/classes/spring/";

                String[] locations = {root+"dispatch-servlet.xml",root+"spring-hibernate.xml",root+"job.xml",root+"task.xml" };
                return locations;
        }

3.然后对具体的XXService, 建立 XXServiceTest extends BaseServiceTest

protected  AdminUserService adminUserService;

        public AdminUserServiceTest(){
                setDependencyCheck(false);
                //setup the directly annotation for the variables to avoid the setters
                setPopulateProtectedVariables(true);
        }       

4.上面是对测试用例中涉及到的成员变量用依赖式注入 初始化

为何在父类中能找到那些 *.xml

在测试用例中,却报以下Exception,求助............


org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:d:/work/stestook/web/WEB-INF/classes/spring/dispatch-servlet.xml]; nested exception is java.io.FileNotFoundException: d:\work\testook\web\WEB-INF\classes\spring\dispatch-servlet.xml (系统找不到指定的路径。)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
        at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:242)
        at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:212)
        at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:187)
        at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:140)
        at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:100)
        at junit.framework.TestCase.runBare(TestCase.java:128)
        at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:120)
        at junit.framework.TestSuite.runTest(TestSuite.java:230)
        at junit.framework.TestSuite.run(TestSuite.java:225)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.io.FileNotFoundException: d:\work\testook\web\WEB-INF\classes\spring\dispatch-servlet.xml (系统找不到指定的路径。)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
        at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
        at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:123)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
        ... 25 more

[ 本帖最后由 ilysony 于 2008-9-12 09:53 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2008-9-12 10:06:34 | 只看该作者
本来默认的Eclipse class文件输出目录是bin,我把输出目录改成classes后,上面的*.xml文件能找到了

但是却出了以下错误,那个webapp.root是tomcat内自己的变量,不知道有没有兄弟有这方面的经验,

真是郁闷,怎么进行spring测试啊

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'tempPath' defined in URL [file:d:/work/stestook/web/WEB-INF/classes/spring/dispatch-servlet.xml]: Could not resolve placeholder 'webapp.root'
        at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)
        at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:554)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:528)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:363)
        at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:243)
        at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:212)
        at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:187)
        at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:140)
        at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:100)
        at junit.framework.TestCase.runBare(TestCase.java:128)
        at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:120)
        at junit.framework.TestSuite.runTest(TestSuite.java:230)
        at junit.framework.TestSuite.run(TestSuite.java:225)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-20 19:39 , Processed in 0.079966 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表