业务要求需要二次开发jeecms平台,为了单元测试折腾了好长时间,就此记下:
添加jar包如下

链接:https://download.youkuaiyun.com/download/ma10851051y/10309003
新建类 代码如下:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:WEB-INF/config/application_Junit.xml",
"classpath*:WEB-INF/config/captcha-context.xml",
"classpath*:WEB-INF/config/shiro-context.xml",
"classpath*:WEB-INF/config/cache-context.xml",
"classpath*:WEB-INF/config/jee*.xml",
"classpath*:WEB-INF/config/jeecms/jee*.xml"})
/*
classpath*:config/application-context.xml",
"classpath*:config/cache-context.xml",
"classpath*:config/captcha-context.xml",
"classpath*:config/jeecore-context.xml",
"classpath*:config/jeecms-context.xml
*/
public class UnitTest {
@Autowired
@Before //在每个测试用例方法之前都会执行
public void init(){
}
@After //在每个测试用例执行完之后执行
public void destory(){
}
@Test
//@Transactional //使用该注释会使用事务,而且在测试完成之后会回滚事务,也就是说在该方法中做出的一切操作都不会对数据库中的数据产生任何影响
// @Rollback(false) //这里设置为false,就让事务不回滚
public void testAdd(){
System.out.println(233);
}
}这是application_Junit.xml测试专用的spring配置文件,不要用于服务器启动配置,开始就失败在这个上面 每次单元测试报错Could not resolve placeholder 'jdbc.driver' in string value "${jdbc.driver}"
查遍网络都是说添加<property name="ignoreUnresolvablePlaceholders" value="true" /> 就好了,问题我怎么添加都不行,遂直接新建配置文件不用从properties配置文件读取数据库配置,这样就能愉快的进行单元测试了

本文分享了在Jeecms平台上进行二次开发时遇到的单元测试难题及解决方案,包括特定的Spring配置和自定义测试类。
1920

被折叠的 条评论
为什么被折叠?



