51Testing软件测试论坛

标题: spring的WEB测试,怎么搭建环境??求助 [打印本页]

作者: ilysony    时间: 2008-9-12 09:51
标题: spring的WEB测试,怎么搭建环境??求助
小弟对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 编辑 ]
作者: ilysony    时间: 2008-9-12 10:06
本来默认的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)




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2