更新时间:2022-06-22 01:05:55
一种方法是添加声明一个 bool thisTestFailed
并将其初始化为false。在 catch
块内,添加语句 thisTestFailed = true;
,然后在测试末尾附近添加代码,例如:
One approach is to add declare a bool thisTestFailed
and initialize it to false. Within the catch
blocks add the statement thisTestFailed = true;
then near the end of the test add code such as:
if ( thisTestFailed ) {
Assert.Fail("A suitable test failed message");
}
另一种方法是转换一系列 Assert。 ..
语句进行一系列的 if
测试,然后执行一个 Assert
。有几种方法可以做到这一点。一种方法是:
Another approach is to convert a series of Assert...
statements into a series of if
tests followed by one Assert
. There are several ways of doing that. One way is:
bool thisTestFailed = false;
if ( ... the first assertion ... ) { thisTestFailed = true; }
if ( ... another assertion ... ) { thisTestFailed = true; }
if ( ... and another assertion ... ) { thisTestFailed = true; }
if ( thisTestFailed ) {
Assert.Fail("A suitable test failed message");
}