Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Nowadays, Test Driven Development is the approach for managing big software projects with ease.</p> </blockquote> <p>That is because TDD allows you to make sure after each change that everything that worked before the change still works, and if it doesn't it allows you to pinpoint what was broken, much easier. (see at the end)</p> <blockquote> <p>What is a Unit Test? Is it a comprehensive list of test cases which should be analyzed?</p> </blockquote> <p>A Unit Test is a piece of code that asks a "unit" of your code to perform an operation, then verifies that the operation was indeed performed and the result is as expected. If the result is not correct, it raises / logs an error.</p> <blockquote> <p>So lets us a say i have a class called "Complex Numbers" with some methods in it (lets says finding conjugate, an overloaded assignment operator and an overloaded multiplication operator. What should be typical test cases for such a class? Is there any methodology for selecting test cases?</p> </blockquote> <p>Ideally, you would test all the code.</p> <ul> <li><p>when you create an instance of the class, it is created with the correct default values</p></li> <li><p>when you ask it to find the conjugates, it does finds the correct ones (also test border cases, like the conjugate for zero)</p></li> <li><p>when you assign a value the value is assigned and displayed correctly</p></li> <li><p>when you multiply a complex by a value, it is multiplied correctly</p></li> </ul> <blockquote> <p>Are their any frameworks which can create unit tests for me or i have to write my own class for tests?</p> </blockquote> <p>See <a href="http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page" rel="nofollow noreferrer" title="CppUnit">CppUnit</a></p> <blockquote> <p>I see an option of "Test" in Visual Studio 2008, but never got it working.</p> </blockquote> <p>Not sure on that. I haven't used VS 2008 but it may be available just for .NET.</p> <blockquote> <p>What is the criteria for Units tests? Should there be a unit test for each and every function in a class? Does it make sense to have Unit Tests for each and every class?</p> </blockquote> <p>Yes, it does. While that is an awful lot of code to write (and maintain with every change) the price is worth paying for large projects: It guarantees that your changes to the code base do what you want them to <em>and nothing else</em>.</p> <p>Also, when you make a change, you need to update the unit-tests for that change (so that they pass again).</p> <p>In TDD, you first decide what you want the code to do (say, your complex numbers class), then write the tests that verify those operations, then write the class so that the tests compile and execute correctly (and nothing more).</p> <p>This ensures that you write the minimal code possible (and don't over-complicate the design of the complex class) and it also ensures that your code does what it does. At the end of writing the code, you have a way to test it's functionality and ensuring it's correctness. </p> <p>You also have an example of using the code that you will be able to access at any point.</p> <p>For further reading/documentation, look into "dependency injection" and method stubs as used in unit testing and TDD.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload