Best practice for debug Asserts during Unit testing
Posted
by Steve Steiner
on Stack Overflow
See other posts from Stack Overflow
or by Steve Steiner
Published on 2009-01-03T22:01:03Z
Indexed on
2010/04/07
21:13 UTC
Read the original article
Hit count: 207
Does heavy use of unit tests discourage the use of debug asserts? It seems like a debug assert firing in the code under test implies the unit test shouldn't exist or the debug assert shouldn't exist. "There can be only one" seems like a reasonable principle. Is this the common practice? Or do you disable your debug asserts when unit testing, so they can be around for integration testing?
Edit: I updated 'Assert' to debug assert to distinguish an assert in the code under test from the lines in the unit test that check state after the test has run.
Also here is an example that I believe shows the dilema: A unit test passes invalid inputs for a protected function that asserts it's inputs are valid. Should the unit test not exist? It's not a public function. Perhaps checking the inputs would kill perf? Or should the assert not exist? The function is protected not private so it should be checking it's inputs for safety.
© Stack Overflow or respective owner