Where do you put your unit test?

I favour keeping unit-tests in separate source files in the same directory as production code (#3).

Unit tests are not second-class citizens, their code must maintained and refactored just like production code. If you keep your unit tests in a separate directory, the next developer to change your production code may miss that there are unit tests for it and fail to maintain the tests.

In C++, I tend to have three files per class:

MyClass.h
MyClass.cpp
t_MyClass.cpp

If you’re using Vim, then my toggle_unit_tests plug-in for toggling between source and unit test files may prove useful.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)