Profile photo for Kurt Guntheroth

If you were super-disciplined, you would code unit tests before coding your objects. I’m not that disciplined.

I write the unit test alongside writing my objects. I write a few obvious member functions first, like the constructors and destructor, then write the unit tests that validate those functions. Then I write more unit tests as a way to suss out what the interface should look like, and then code those functions.

Sometimes my unit tests are hard to write because I need to bring in a boatload of other classes. That tells me my class is too strongly coupled. I pass in a pointer or reference to the other class, and all of a sudden I can also write mocks of these classes to provide extra clarity in the tests. Sometimes I find I need a new function at the interface to make the tests work. That’s OK. An interface function useful for testing might be useful in coding interactions with the class too.

View 43 other answers to this question
About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025