C#的Unit Test如何根据exception来判断函数是否执行正确
2013-07-03 15:05
423 查看
添加ExpectedException属性, 然后指定异常类型, catch后决定Assert.IsTrue
The following class contains the method to test:
C#VB
using System; namespace MyCSNamespace { public class DivisionClass { public int Divide(int numerator, int denominator) { return numerator / denominator; } } }The following test method tests the Divide method of the DivisionClass object. It tests for the existence of a DivideByZeroException.
C#VB
using Microsoft.VisualStudio.TestTools.UnitTesting; using MyCSNamespace; namespace MyCSTestProject { [TestClass()] public class DivisionClassTest { [TestMethod()] [ExpectedException(typeof(System.DivideByZeroException))] public void DivideTest() { DivisionClass target = new DivisionClass(); int numerator = 4; int denominator = 0; int actual; actual = target.Divide(numerator, denominator); } } }
相关文章推荐
- C#的Unit Test如何根据exception来判断函数是否执行正确
- C#的Unit Test如何根据exception来判断函数是否执行正确
- 根据JS判断是否执行C#后台代码(后台弹出确定/取消提示窗口)
- Perl脚本学习经验(一)------如何判断执行脚本时的输入参数是否正确
- 在c#.net中,如何判断文本框中的值是否是数字?我想验证身份证输入是否正确。
- system函数返回(如何判断调用的shell命令是否执行成功)
- c# winform中如何判断DataGrid当前选中的是空白行,并根据选择控制按钮是否可用
- 如何根据执行计划,判断Mysql语句是否走索引
- c#中如何判断字符串是否为数字
- C# 根据前台校验的值,决定是否执行后台方法
- Java 如何判断线程池所有任务是否执行完毕
- js如何判断QQ号码是否输入正确?
- 判断PHP的exec函数是否执行成功
- 正则判断正整数等js如何判断输入是否为正整数、浮点数等数字的函数
- C#(用函数判断输入的值是否是数字)
- 【叶子函数分享二十八】根据年度判断是否是闰年
- Java 如何判断线程池所有任务是否执行完毕
- 如何判断一条sql(update,delete)语句是否执行成功
- C语言中如何编写判断结构体是否相等的函数