Different Test Examples in C++ Using C++ CppUTest 16

Posted by Brett Schuchert Thu, 26 Mar 2009 23:08:00 GMT

Here are several versions of the same unit tests written in different styles using CppUTest: C++ Unit Test Examples. If you look near the bottom, you’ll see what looks like story tests in C++. Shocking!

These are all based on Bob’s Prime Factors Kata.

Comments

Leave a response

  1. Avatar
    Markus Gärtner 1 day later:

    While reading through your example, I realized that the And method in your bdd first example does not call report with the message. While reading through the second bdd example I realized that this was not intended, but distracted me while reading the first one a bit.

  2. Avatar
    Markus Gärtner 1 day later:

    While reading through your example, I realized that the And method in your bdd first example does not call report with the message. While reading through the second bdd example I realized that this was not intended, but distracted me while reading the first one a bit.

  3. Avatar
    Brett L. Schuchert 1 day later:

    Markus Gärtner wrote:

    While reading through your example, I realized that the And method in your bdd first example does not call report …

    Thanks, distraction removed for any future reader.

    In reality, I put the report method in as strictly a hook method. In the version I wrote on the plane ride, the report method stored information in a singleton object. I then registered an at exit function to summarize the results.

    However, when I did this, CppUTest complained of leaked memory when I ran my unit tests. I have not gone back to fix that since I know in this case that the memory “leak” is by design … I want to record what is happening and then report at the end of the life of the system. I could store the results in a temporary file and then report the contents at the end, but given I was just experimenting with forms of tests, it did not seem worth it.

    I kept the report(...) method in there as a “use” of the passed in string. However, the intention is to make the BDD style more expressive. I didn’t want to make it expressive without showing a candidate use of the first parameter (the message).

  4. Avatar
    ?????? 3 months later:

    ? ?? ?? ?? ????

  5. Avatar
    ?????? 4 months later:

    wanderful post.. i love it!

  6. Avatar
    ed hardy 6 months later:

    I dont even remember how i reached your site but it doesnt matter, cause i’m so happy i found it, it really made me think, keep up the good work.

  7. Avatar
    Inpatient Drug Rehab 7 months later:

    Thank you very much for sharing such a useful post.

  8. Avatar
    tic-tac 8 months later:

    Great – thank u!

  9. Avatar
    games 8 months later:

    10x

  10. Avatar
    olgames 8 months later:

    great one

  11. Avatar
    nike shoes hosting 8 months later:

    I put the report method in as strictly a hook method. In the version I wrote on the plane ride, the report method stored information in a singleton object. I then registered an at exit function to summarize the results.

  12. Avatar
    games 9 months later:

    games for family .

  13. Avatar
    gucci louis vuitton shoes 9 months later:

    Welcome to Freshstyleshop, the hottest urban clothing site on the net! We offer great products from Gucci sneakers, prada sneakers, LV shoes, True Religion Jeans and many more! Our selection of products are always increasing for the fact that we have new items added weekly to our selection. All products on our site are already marked down 40-60% off retail price. Freshstyleshop also backs all its orders with a 110% satisfaction guarantee, making sure that our customers are left satisfied with the hottest products on the net.

  14. Avatar
    money 10 months later:

    a lot to learn from your posts and comments on your site, thank you.

  15. Avatar
    http://www.net-gaming.net 10 months later:

    if you love play games

  16. Avatar
    http://www.amigo-play.com 11 months later:

    games for everyone!

Comments