mardi 20 janvier 2015

Should we test src code assertions (NOT exceptions) in C++ unit test?

I have heard conflicting views from several people in this regard, and wanted to see what the stackoverflow community thinks about this.


The people in the yes side says:

- We should test assertions , since it gives us code coverage

- What if tomorrow some new programmer comes and takes out the assertion by mistake, and if there is no test to catch it. We should be testing assertions as such.


The people on the no side says

- I don't see how it is helpful to test when the program exits and testing this is fairly expensive. For example, in google test framework, we fork a child process and run the death test there and make the parent process to wait for result for child process. This is fairly expensive testing. In a multithreaded environment testing assertions are more expensive. As such this kind of expensive testing which gives such minimal value is not worth it.

- If there is a code path that leads to assertion in src, during build/run time we will catch that and get the stack trace. As such , we will have all the information needed to debug as to why the assertion is being hit. As such creating unit tests that only tests basic assertions is not really helpful.


What are your thoughts?


Aucun commentaire:

Enregistrer un commentaire