Junit 入门(二)
来源:互联网 发布:switch网络一会b一会f 编辑:程序博客网 时间:2024/06/05 17:21
1.获取最大值类
package com.ebuair.junit;public class MaxValue {public int getMaxValue(int[] array) throws Exception{if(null == array || array.length == 0){throw new Exception("数组不能为空");}int maxValue = array[0];for(int i = 1; i < array.length; i++){if(maxValue < array[i]){maxValue = array[i];}}return maxValue;}}
2.测试类
package com.ebuair.junit;import junit.framework.Assert;import junit.framework.TestCase;public class TestMaxValue extends TestCase{private MaxValue maxValue = null;@Overridepublic void setUp() throws Exception {maxValue = new MaxValue();}public void testGetMaxValue(){int largetValue = 0;int[] array = new int[]{12,34,56,7,8};try {largetValue = maxValue.getMaxValue(array);} catch (Exception e) {Assert.fail("测试失败");}Assert.assertEquals(56, largetValue);}public void testGetMaxValueByNoValue(){Throwable throwable = null;int[] array = {};int largestValue = 0;try {largestValue = maxValue.getMaxValue(array);Assert.fail();} catch (Exception e) {throwable = e;}Assert.assertNotNull(throwable);Assert.assertEquals(Exception.class, throwable.getClass());Assert.assertEquals("数组不能为空", throwable.getMessage());}public void testGetMaxVauleByNull(){Throwable throwable = null;int[] array = null;int largestValue = 0;try {largestValue = maxValue.getMaxValue(array);Assert.fail();} catch (Exception e) {throwable = e;}Assert.assertNotNull(throwable);Assert.assertEquals(Exception.class, throwable.getClass());Assert.assertEquals("数组不能为空", throwable.getMessage());}}
0 0
- Junit 入门(二)
- Junit和Ant入门(二) Ant
- 【转】JUnit(二)
- Junit使用指南(二)
- Junit和Ant入门(一) JUnit
- 【Junit】Junit使用教程(二)
- junit 简单介绍(入门)
- Junit入门(java测试)
- JUnit源码分析(二)
- Junit使用教程(二)
- Junit使用教程(二)
- Junit使用教程(二)
- JUnit + Mockito 单元测试(二)
- Junit使用教程(二)
- Junit使用教程(二)
- Junit使用教程(二)
- Junit使用教程(二)
- Junit使用教程(二)
- UML 类图
- Java Proxy InvocationHandler invoke理解
- MFC下unsigned char和Cstring的转换
- 智能手表开发API接口之我见
- 如何在VS 编译器下 使用纯 C 语言编译器?
- Junit 入门(二)
- [LeetCode]Partition List
- ComboBox消息打开列表
- 安卓实训第九天---Activity的复习以及在Onstart里设置网络连接
- 没有方向了?
- Stopping and Restarting an Activity 停止和重新启动活动
- WIN7下VMware+Ubuntu配置上网(对无线网络也有效)
- [二次开发] 饭窝网重磅出击 “图文菜谱discuz二次开发应用”
- 使用CountdownTimer进行倒计时