开发者

writing testcases for classes in my c++ program running on linux

I am a beginner for writing test-cases so i don't know about test-cases, can you briefly explain about test-cases and also, how can i write test-cases for my c++ program(classes开发者_JAVA百科,member functions,member variables,....) help me in writing those and compiling and running it.

Advance in thanks


First of all:

  1. First find your self a framework of your liking: wikipedia list of frameworks here
  2. Install and read its documentation
  3. Identify the invariants, valid and invalid input of your methods and write tests that makes sure that they are enforced. My recommendation is to write tests that test in a black box way. I.e. you do not care how the methods does it, but you check that the results are ok with good input (corner cases and a normal case) and also that it fails in a good way when the input is bad.
  4. This answer elaborates on how to write good tests

Some general advice:

  • Write tests that will either fail or not, writing tests that probably will fail when something is wrong is a pita.
  • Never trust a test that you haven't seen fail.
  • Write one test at the time
  • Try to keep the testcases as autonomous as possible. Make sure that you test the code submitted to testing, not it's infrastructure. Unit testing is a great way to make sure that your classes depends on interfaces.
  • It is most often a bad idea to test implementation details of a method. You do not want tests to fail when someone rewrites the code correctly. If you feel the need to test the implementation you probably have another class hiding in the code that also should be unittested.


Cxxtest is useful indeed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜