|
小弟对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 编辑 ] |
|