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:
- First find your self a framework of your liking: wikipedia list of frameworks here
- Install and read its documentation
- 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.
- 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.
精彩评论