Maven实践(四):Maven+Junit单元测试竟如此畅快
使用Maven+Junit做单元测试竟是如此畅快。只需要几步就完成了单元测试。
1、编写单元测试
在src/test/java下编写单元测试,可以编写N个测试。下面是其中一个。
public class OrderTest extends TestCase { private ApplicationContext ac; private MyorderDao dao; public MyorderDao getDao() { if (dao == null) { dao = (MyorderDao) ac.getBean("myorderDao"); } return dao; } /** * 测试分页查询 */ public void testQueryPaging() { Myorder example = new Myorder(); ... ... List<Myorder> orderList = getDao().selectByExamplePaging(example); for (Myorder myorder : orderList) { ... ... } } protected void setUp() throws Exception { ac = new ClassPathXmlApplicationContext("applicationContext-dao.xml"); super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); ac = null; } }
2、Maven运行单元测试
cd到项目目录运行:mvntest
执行maven命令后做所有的类和方法的测试并打印测试结果
相关推荐
bobljm 2020-07-07
84224552 2020-05-31
snowphy 2020-05-30
snowphy 2020-05-12
蛰脚踝的天蝎 2020-11-10
Cocolada 2020-11-12
TuxedoLinux 2020-09-11
snowphy 2020-08-19
83540690 2020-08-16
lustdevil 2020-08-03
83417807 2020-07-19
张文倩数据库学生 2020-07-19
83417807 2020-06-28
86427019 2020-06-28
86427019 2020-06-25
zhengzf0 2020-06-21
tobecrazy 2020-06-16
宿命java 2020-06-15