Unit Testing without Assertions

后端 未结 14 2374
夕颜
夕颜 2020-12-17 08:35

Occasionally I come accross a unit test that doesn\'t Assert anything. The particular example I came across this morning was testing that a log file got written to when a co

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 08:51

    I sometimes use my unit testing framework of choice (NUnit) to build methods that act as entry points into specific parts of my code. These methods are useful for profiling performance, memory consumption and resource consumption of a subset of the code.

    These methods are definitely not unit tests (even though they're marked with the [Test] attribute) and are always flagged to be ignored and explicitly documented when they're checked into source control.

    I also occasionally use these methods as entry points for the Visual Studio debugger. I use Resharper to step directly into the test and then into the code that I want to debug. These methods either don't make it as far as source control, or they acquire their very own asserts.

    My "real" unit tests are built during normal TDD cycles, and they always assert something, although not always directly - sometimes the assertions are part of the mocking framework, and sometimes I'm able to refactor similar assertions into a single method. The names of those refactored methods always start with the prefix "Assert" to make it obvious to me.

提交回复
热议问题