在我在Nunit的测试程序中,我想通过验证消息来验证它是否正在获取写入Argument Exception.
[Test]
public void ArgumentsWorkbookNameException()
{
const string workbookName = "Tester.xls";
var args = new[] { workbookName, "Sheet1", "Source3.csv", "Sheet2", "Source4.csv" };
Assert.Throws(typeof(ArgumentException), delegate { var appargs = new ApplicationArguments(args); }, "Invalid ending parameter of the workbook. Please use .xlsx");
}
Run Code Online (Sandbox Code Playgroud)
在测试完之后,当我在主程序中修改消息时,这不起作用.
int wbLength = args[0].Length;
// Telling the user to type in the correct workbook name file.
if (args[0].Substring(wbLength-5,5)!=".xlsx")
{
throw new ArgumentException(
"Invalid ending parameter of the workbook. Please use .xlsx random random");
}
Run Code Online (Sandbox Code Playgroud)
无论我是否更改了消息,单元测试仍然通过.
我该怎么做?或者C#中没有这样的东西.我的同事说Ruby和RSPEC都有类似的选项,但他对C#并不是100%肯定.