Comments on: Specification-based Test Design Techniques for Enhancing Unit Tests Part 1 https://simpleprogrammer.com/specification-based-test-design-techniques-enhancing-unit-tests-part-1/ Tue, 12 Jun 2018 16:54:16 +0000 hourly 1 https://wordpress.org/?v=7.0 By: dotnetchris https://simpleprogrammer.com/specification-based-test-design-techniques-enhancing-unit-tests-part-1/#comment-4016 Fri, 07 Aug 2015 16:55:00 +0000 https://simpleprogrammer.com/?p=14034#comment-4016 I don’t think i’ve ever met a developer in my entire career that strives for 100% code coverage. 100% code coverage is a lunacy metric. Why would i ever test a parameter condition such as if(arg1 == null) throw new ArgumentNullException(“arg1”)? To achieve 100% coverage i have to instrument that path. What value do i gain from it? I know it’s going to throw an exception.

In almost all situations it’s pointless to test code paths that result in unhandled exceptions, they’re by definition exceptional and unhandleable. This would be akin to trying to make code that uses File.ReadAllText throw an exception for a damaged sector on a hard drive. Is it remotely feasible you COULD do it? Yes. Will you gain anything? No. The only reason you would ever do something like that is if you are testing code to be tolerant of the exceptions. Like backup software, you probably want it to handle every kind of disk error possible and at the end display what failed instead of abandoning it in the middle.

]]>