I wrote the Matrix class and verified that it forbade multiplication of matrices of incompatible sizes using C ++ exceptions. I wrote unit tests to test this behavior, and they expect an exception.
Now I resize the matrix as a run-time variable in the template parameter. If I can do it right, code that tries to multiply matrices of the wrong size will not even compile.
It would seem that now these unit tests are redundant. However, since I don’t know how I will change my code in the future, and what will break, I still want to run tests for this. If I had previously expected my tests to throw specific exceptions in specific places, now I want my test to throw specific compilation errors in specific places.
What is the best way to do this? I would suggest some kind of mechanism based on Makefile and shell scripts that will wait for specific error codes - or should I try something else? Is this idea a common practice or complete insanity?
Change Of course, “Unit tests” are not suitable for such a mechanism, I know this, but so far I just can’t think of a better way. There are already three commentators who have spent their valuable time and effort explaining to me what unit tests are and which are not. Unfortunately, although this is technically true, it does not help solve the real problem.
Change 2 . This is a BDD script that I want to test for:
- Given two matrices of sizes 2x2 and 3x3
- When a user tries to propagate them
- Then it receives an error message
Previously, this error was a run-time error, and testing for it was trivial. But now I have become a compile-time error, and I don’t see how I can automatically check this script and confirm, with every commit (I have unit tests in my git hooks) that still give me an error.
source share