简体   繁体   中英

NUnit: Is it possible to configure NUnit that a Test fails, if no Assert has executed

I am using NUnit . Is it possible to configure NUnit in a way, so that every UnitTest fails that does not call at least once an Assert-Method?

So I can prevent some cases of invalid UnitTests.

Based on this discussion it does not appear to be possible. Admittedly this is from 3 years ago but I do not think the answer has changed.

Stated simply, there's no setting such as you are looking for. I recall that we discussed the possibility a long time ago on the old SourceForge mailing list and that the general opinion at the time was for an empty test to simply succeed. One reason is that some people were writing tests in which all the Asserts were conditional and didn't want to see a failure if none were applicable. Of course, the biggest reason is that NUnit is oriented toward TDD, even if not exclusively. So the general community of users does not usually have a bunch of empty tests.

A 'bug' was created for adding support for a command line option to enable this feature but it does not appear to have any activity since 2013. I cannot see any corresponding issue on the nUnit Github though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM