ssh(spring,struts2,hibernate)框架整合junit4
2021-06-30 23:06
阅读:568
标签:rtti apt step ted getbean bean cep 整合 etc
step1:导入必须的包,如果是maven项目,直接在pom.xml文件里加入以下依赖包:
junit junit4.12 test org.springframework spring-test2.5.5 test org.apache.struts struts2-junit-plugin2.3.15.1 test javax.servlet jsp-api2.0 test
step2:在src/main/java下建测试类
step2.1:测试action
//测试action的类需要继承StrutsSpringTestCase public class JunitTrackActionTest extends StrutsSpringTestCase{ @Test public void test() { //设置 请求参数 request.setParameter("startTime", "2018-09-11 00:00:00"); request.setParameter("endTime", "2018-09-11 12:00:00"); request.setParameter("queryReliability", "99"); try { //括号里的是前台发送的url连接 String result = executeAction("/trackAction!getTrackByParams.action"); System.out.println(result); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ServletException e) { e.printStackTrace(); } } }
step2.2:测试service
public class JunitTrackServiceTest { private String startTime; private String endTime; private String queryReliability; private TrackService trackService; @Before public void init() { ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml"); trackService = (TrackService) classPathXmlApplicationContext.getBean("trackService"); startTime = "2018-09-11 00:00:00"; endTime = "2018-09-11 12:00:00"; queryReliability = "99"; } @Test public void test() { List
step2.3:测试dao
public class JunitTrackDaoTest { private String startTime; private String endTime; private String queryReliability; private TrackDAO trackDAO; @Before public void init() { ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml"); trackDAO = (TrackDAO) classPathXmlApplicationContext.getBean("trackDAO"); startTime = "2018-09-11 00:00:00"; endTime = "2018-09-11 12:00:00"; queryReliability = "99"; } @Test public void test() { List
最后,点击鼠标右键--》run as--->JUnit Test,即可
ssh(spring,struts2,hibernate)框架整合junit4
标签:rtti apt step ted getbean bean cep 整合 etc
原文地址:https://www.cnblogs.com/bingyimeiling/p/9639789.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:ssh(spring,struts2,hibernate)框架整合junit4
文章链接:http://soscw.com/essay/100060.html
文章标题:ssh(spring,struts2,hibernate)框架整合junit4
文章链接:http://soscw.com/essay/100060.html
评论
亲,登录后才可以留言!