Reputation: 1767
Unit testing with C/C++: What do you teach people who either did not do unit testing before or come from Java/Junit?
What is the single most important lesson / thing to remember/ practice from your point of view that saves a lot of time or stress (especially regarding C/C++)?
Upvotes: 9
Views: 705
Reputation: 21644
I'm against all of these recommendations for automatically granting friendship to test classes...
Personally I prefer to focus on the following to allow me access to the insides of a class that I need to test:
In summary, I much prefer to see designed in test points rather than a blanket friendship with a test class. Of course the former is harder to do than the latter but, IMHO, results in better code AND better tests.
Upvotes: 3
Reputation:
In the case of dealing with legacy code base with no tests, you will most probably start (as I had to) with functional tests that use a unit test framework for implementation. Don't be alarmed - your code is so interconnected that it's probably impossible to write proper unit tests. Don't be complacent, either - once functional tests are in place, you need to refactor so that true unit tests are possible. Your code will be better for it!
Upvotes: 2
Reputation: 49687
A unit test case should only test one thing.
I see it much more often in C/C++ compared to C# and Java that unit test cases test entire workflows.
Perhaps it is because most C/C++ xUnit frameworks require several steps to register a testcase, so the temptation to just add a few lines to an existing testcase when adding a new feature is higher.
Upvotes: 1
Reputation: 16486
Single most important lesson: A test is better than no test.
Upvotes: 1
Reputation: 8620
I'd like to rephrase ripper234 and add some more rules:
Upvotes: 2
Reputation: 230316
Upvotes: 9