adobe photoshop cs4 中文版-好友恢复系统
2023年4月2日发(作者:word页码设置)
Spring教程第⼆篇:Spring-Test(单元测试)
在Spring的框架下,做单元测试的两种办法:
⼀、使⽤spring中对Junit框架的整合功能
除了junit4和spring的jar包,还需要。引⼊如下依赖:
@ContextConfiguration需要配上spring的配置⽂件,这样就可以在测试类中使⽤注解简单的注⼊需要的bean了。简单⾼效,Java代码
如下:
⼆、⼿动加载spring的配置⽂件,并启动spring容器
Spring-Test中遇到的常见问题:
1.下载的要和⾃⼰下载的spring项⽬的版本号⼀致,否则会以下报错
@RunWith()
@ContextConfiguration({"classpath:"})
publicclassReadDaoImplTest{
@ResourceReadDaoreadDao;
@Test
publicvoidgetListTest(){
List
for(Clientc:clientList){
n(sionNum());
}
}
}
publicclassReadDaoImplTest{
publicstaticvoidmain(String[]args){
ClassPathXmlApplicationContextcontext=newClassPathXmlApplicationContext("");
();
ReadDaofqaService=(ReadDao)n("readDao");
n(fqaService);
}
}
2.也许你还会遇到诸如⽂件找不着的错误解决⽅法如下,错误紧接着贴出如下
@ContextConfiguration(locations={“file:WebRoot/WEB-INF/”})//WEB-INF下读取⽅式
//@ContextConfiguration(locations={“classpath:test/”})//类路径下有个test包下
lStateException:CouldnotloadTestContextBootstrapper[null].Specify@BootstrapWith's'value'attributeormakethedefaultbootstrapper
eTestContextBootstrapper(:160)
ntextManager.
TestContextManager(:154)
JUnit4ClassRunner.
tance0(NativeMethod)
tance(:57)
tance(:45)
tance(:526)
unner(:29)
ForClass(:21)
nnerForClass(:59)
ForClass(:26)
nnerForClass(:59)
ner(:26)
4TestReference.
4TestClassReference.
Test(:48)
sts(:38)
ts(:452)
ts(:683)
(:390)
(:197)
Causedby:sDefFoundError:org/springframework/core/annotation/AnnotatedElementUtils
eTestContextBootstrapper(:127)
...21more
Causedby:otFoundException:tedElementUtils
ssLoader$(:366)
ssLoader$(:355)
ileged(NativeMethod)
ass(:354)
ass(:425)
er$ass(:308)
ass(:358)
...22more
lStateException:FailedtoloadApplicationContext
licationContext(:157)
Dependencies(DependencyInjectionTestExecutionListener
eTestInstance(DependencyInjectionTestExecutionListene
eTestInstance(:321)
Test(:211)
JUnit4ClassRunner$lectiveCall(:288)
(:12)
Block(:290)
ld(:231)
ld(:50)
Runner$(:238)
Runner$le(:63)
ldren(:236)
$000(:53)
Runner$te(:229)
te(:61)
te(:71)
(:309)
(:174)
(:50)
(:38)
ts(:467)
ts(:683)
(:390)
(:197)
Causedby:finitionStoreException:IOExceptionparsingXMLdocumentfromclasspathresource[test/test/appli
anDefinitions(:341)
anDefinitions(:302)
anDefinitions(:174)
anDefinitions(:209)
anDefinitions(:180)
anDefinitions(:243)
anDefinitions(:205)
ntext(:100)
ntext(:1)
ntext(:228)
plicationContext(:124)
licationContext(:148)
...24more
Causedby:tFoundException:classpathresource[test/test/]cannotbeopenedbecauseitdoesnotexist
utStream(:157)
anDefinitions(:328)
...35more
更多推荐
test exe
发布评论