Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Xeee

A Question about Unit Testing Frameworks

This topic is 5364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

after reading alot about refactoring, i realized the importance of testing, and as i knew about testing, i heard about unit testing frameworks(junit, cppunit, unit ++, etc). to set up a test using any of these libraries, it takes up effort and time(you make a class derived from test_case, and override a virtual function) and i don''t see the point behind that, why not just use a simple assert() or printf() to confirm that all your tests ran successfully. something like that: assert(Add(5, 4) == 9); // Add(int, int) function test. thanks for care xee..

Share this post


Link to post
Share on other sites
Advertisement
As you say, they are just frameworks. They are designed to help make testing easier, allowing you to group and run tests. You still have to write the individual tests yourself and the frameworks can often complicate matters and end up including parts of the langauge you may not want to use (e.g. exception handling in c++). For large scale projects that need to be rigorously tested they can save time and effort. On a smaller scale it is easier and often quicker to write your own tests for classes as you write them.

Assert is an invaluable tool, in each test you hould use it to test the pre and post conditions, e.g. check that all inputs are in the expected range (pointers are not null etc.) and that the output is as expected.

This article on CodeProject.com may help. It describes testing using cppunit, but also has some more general info on designing tests.

Share this post


Link to post
Share on other sites
quote:
Original post by Xeee
why not just use a simple assert() or printf() to confirm that all your tests ran successfully.

something like that:

assert(Add(5, 4) == 9); // Add(int, int) function test.

But that''s exactly what those frameworks do...

Share this post


Link to post
Share on other sites
You can keep adding more and more suites and all the tests keep getting run. You can refactor the tests too! So you get rid of redundant and error prone code in your tests as well as your real code. They''re not a silver bullet and require discipline, but they do speed things up as you''re getting consistant feedback. You become aware of making progress.

If you write tests as you go along its not such a chore but if you go and retro-fit your tests it definitely is tedious. Once you''ve got them in place the fun starts but it can be difficult to maintain the discipline to get there.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!