[英]how I attribute unit test with data driven and expected exception
I have a unit test function, which attribute as 'datadriven'. 我有一个单元测试功能,其属性为“数据驱动”。 it calls another function that expected to throw an exception.
它调用另一个可能引发异常的函数。 if i attribute the both first method or the twice with "ExpectedException" it fails, and doesn't continue with the other rows on the data source.
如果我将第一个方法或两次方法都赋予“ ExpectedException”属性,它将失败,并且不会继续使用数据源上的其他行。 what should I do?
我该怎么办?
You can use the Assert.Throws()
method in NUnit to verify that a method within your test throws an exception. 您可以在NUnit中使用
Assert.Throws()
方法来验证测试中的方法是否引发异常。
Assert.Throws<FileNotFoundException>(() => ThisMethodThrowsFileNotFound());
The ExpectedException
attribute is meant to be used on the test method (the one with the Test
attribute). ExpectedException
属性用于测试方法(具有Test
属性的一种)。 Decorating any other method with it has no effect. 用它装饰任何其他方法均无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.