C#的Unit Test如何根据exception来判断函数是否执行正确
2013-07-10 15:42
459 查看
添加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来判断函数是否执行正确
- c# winform中如何判断DataGrid当前选中的是空白行,并根据选择控制按钮是否可用
- 根据JS判断是否执行C#后台代码(后台弹出确定/取消提示窗口)
- system函数返回(如何判断调用的shell命令是否执行成功)
- 如何根据执行计划,判断Mysql语句是否走索引
- Perl脚本学习经验(一)------如何判断执行脚本时的输入参数是否正确
- 在c#.net中,如何判断文本框中的值是否是数字?我想验证身份证输入是否正确。
- js如何判断输入是否为正整数、浮点数等数字的函数
- 如何判断apache与tomcat整合的是否正确?
- C#实现如何判断一个字符串是否为整数和浮点
- C# 对于执行时间较长函数,如何显示“处理中...”
- C#datetime判断日期输入是否正确
- WindowMobile如何判断网络有没连接和如何判WebService服务器地址是否正确(wifi有无打开)
- C#如何判断某个文件夹是否为共享,访问权限为只读
- JS如何判断函数的形参个数与实参个数是否相等
- C#判断IP地址是否合法函数-使用正则表达式-2个,还有IPAddress
- 实测如何使用c#代码判断服务器是否安装iis
- 如何判断用户输入的邮箱格式是否正确?
- C# 如何判断字符串中是否包含另一个字符串?