????????spring?????м???????
????1??AbstractSpringContextTests??[1]???????????????protected????????????????????????????????
????2??AbstractDependencyInjectionSpringContextTests??[2]?????????[1]??????N???????????????Spring???????????????ò?????????и???
????3??AbstractTransactionalSpringContextTests??[3]:???????[2]????и?????????????spring??????????н??У?????????????????????????κ????????????????Щ?????????????????????????????????????????????????κ????
????4??AbstractTransactionalDataSourceSpringContextTests?????????[3]??????????????????ò????????????????????"protected JdbcTemplate jdbcTemplate;"?????????JdbcTemplate?????????????????????????????
????[url]http://lighter.iteye.com/blog/41733[/url] ????????????spring?????м??????(?????????????в???)????????(????????в???)????????????
????***????????TestCase Class?????spring context (???·??????)??***
???????TestCase Class?????е??????????AbstractXXXSpringContextTests?е????????????????????????????????????spring context??
????protected abstract String[] getConfigLocations();
???????磺
public String[] getConfigLocations() {
String[] configLocations = { "applicationContext.xml"??"hibernate-context.xml" };
return configLocations;
}
?????? ?????????context xml file??·????????????????????classpath?????applicationContext.xml??hibernate- context.xml???????classpath??????????xml files???WEB-INF/classes???£?????????????project properties???xml files??·?????classpath??
??????????????????context xml files???WEB-INF???£??????????????????file(????file?????·?????????project root folder)?????????£?
public String[] getConfigLocations() {
String[] configLocations = { "file:WebContent/WEB-INF/applicationContext.xml"};
return configLocations;
}
????AbstractXXXSpringContextTests????????getConfigLocations?????????context xmlλ?????????????????????Context?????檔 ????????????????????????????????????????????????????????????Spring???????????????Spring??????????????????? ????????????????????磬???????50-100??Hibernate??????????????????10-20?????????????????????????????????????? ????fixture????????????????????????????????????????????????????????п??????????????????Ч???
??????????????????£???????????“ū??”?????ó?????????????????????????????bean???????????????????????????????? AbstractDependencyInjectionSpringContextTests ??? setDirty() ????????????????ò??????????????????????application context
???????? AbstractDependencyInjectionSpringContextTests????????????????Application Context???????????Setter????????????????????context??bean?????????????????applicationContext.getBean(XXX)?????AbstractDependencyInjectionSpringContextTests???getConfigLocations()?????????????????а?????????
??????????????????setter?????????context???ProductManager bean??
public class MyTest extends AbstractDependencyInjectionSpringContextTests {
ProductManager productManager;
public String[] getConfigLocations() {
String[] configLocations = { "file:WebContent/WEB-INF/applicationContext.xml" };
return configLocations;
}
public void testGetProduct() {
assertEquals("tomson"??productManager.getProductByName("tomson").getName());
}
//???setter?????????context?????productManager bean???????????????applicationContext.getBean(XXX)
public void setProductManager(ProductManager productManager) {
this.productManager = productManager;
}
}