【mstest实现类似单元测试nunit中assert.throws功能】教程文章相关的互联网学习教程文章

mstest实现类似单元测试nunit中assert.throws功能

我们做单元测试NUnit中,有一个断言Assert.Throws很好用,但当我们使用MsTest时你需要这样写: 代码如下:[TestMethod][ExpectedException(typeof(ArgumentNullException))]public void WriteToTextFile(){PDFUtility.WriteToTextFile("D:\\ACA.pdf", null);} 现在让我们来扩展一下也实现类似成功能,增加一个类,代码如下: 代码如下:/// <summary>/// Useful assertions for actions that are expected to throw an exception./// </sum...

我如何安全地在ASP.NET中进行Debug.Assert?【代码】

无法断言资产.这很好,因为我不想将某些错误包装在try / catch中,至少在开发服务器上没有包装.但是Asserts似乎很危险.如果他们投入生产,它可以使用msgbox挂起ASP.NET服务器.//Don't want this on prod even if debug=true is in the web.config #if DEBUG//A future client programmer can wrap this in a try{}catch{}if (!EverythingIsOkay)throw new InvalidOperationException("Dagnabbit, programming error");//This stops th...