开发者

Specify an output message for successful test case

开发者 https://www.devze.com 2023-03-16 13:05 出处:网络
Each 开发者_如何学编程Assert allow to define error message which will be printed out in case of assert failure but can I somehow provide a message which will be outputed in case of successful test run

Each 开发者_如何学编程Assert allow to define error message which will be printed out in case of assert failure but can I somehow provide a message which will be outputed in case of successful test run?


I just use Console.WriteLine( "Your message here" ); which will be directed to the NUnit output so you can see Test passed messages


You can use the Assert.Pass utility method.


You've said that you want this information for use by your continuous integration environment. Presumably your CI environment is using the NUnit-console Runner?

If so then I recommend making use of the XML output generated from each test run, and example of which can be found here.

The XML output contains results for each and every test. You haven't said which CI server you're using, but it should be straightforward to build a step into your build process to import this XML and mine it for the stats you need.


You should handle the NUnit.Framework.SuccessException and print the message:

try
{
    // assert
    Assert.Pass(sOutput);
}
catch (SuccessException ex)
{
    Console.WriteLine(ex.Message);
    return;
}

As a result you should get the output message under clicking Output:

Specify an output message for successful test case

0

精彩评论

暂无评论...
验证码 换一张
取 消