使用Junit等工具进行单元测试
一. 类的定义
二. JUnit项目引入
三. 生成JUnit测试框架
四. 测试代码结果截图
五.记录各个阶段的时间
六.将测试过程记录在个人博客上(包括Github地址)
一.类的定义:建立好java项目后,先定义一个类,名字为test。
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907161413044-27269009.jpg)
2.编写test类中的方法:先定义变量m、n,编写方法比较两个变量的大小。
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907161501044-2132406706.jpg)
3.右键点击test,弹出对话框,选择properties,在弹出的对话框中选择Java build path,再选择libraries,点击add library,弹出对话框后,选择junit,继而再选择junit4,点击完成,junit就被添加到项目中了。
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907163328278-1135924521.jpg)
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907163556903-1127828824.jpg)
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907163744512-1536414585.jpg)
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907163852778-1570798616.jpg)
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907163949528-2112570629.png)
4.右键点击test,在弹出的对话框中选择new--》junit test case,新建一个用来测试代码的类,选择所要测试的方法。
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907164521653-1813547562.jpg)
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907164625200-156130657.jpg)
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907165039122-1378933378.jpg)
5.编写测试代码。
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907164811294-1317316501.jpg)
6.点击testTest, 选择run as -->junit test.
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907165308497-1888818426.jpg)
![](https://images2015.cnblogs.com/blog/804954/201509/804954-20150907165427684-1232982706.jpg)
7.记录各个阶段的时间
程序计划:5
程序设计:10
程序编码:10
程序测试:10