Unit Testing Frameworks for C++

Hi Community,

This is the first post for  August 2010 and I must say that “This year has flown by” and I’ve been pretty busy in  Melbourne lately. A few days ago my mate and peer Simon Waight flicked me an email about  this very interesting Unit Test Framework for C++ called Isolator++ which in my humble opinion has a lot to offer, a basic code snippet using this framework is shown below

   1: int Product::GetPrice(PricingManager* manager)

   2: {

   3:       if (manager->isOnSale())

   4:             return 5;

   5:       else

   6:             return 10;

   7: }

   8:  

   9:  

  10: bool PricingManager::isOnSale()

  11: {

  12:      return false;

  13: }

  14:  

  15:  

  16: TEST_F(IsolatorTests, GetPrice_OnSaleIsFalse_ExpectHighPrice)

  17: {

  18:      Product product;

  19:      PricingManager* manager =  new PricingManager();

  20:      ASSERT_EQ(10, product.GetPrice(manager));

  21: }

  22:  

  23:  

  24: TEST_F(IsolatorTests, GetPrice_OnSaleIsTrue_ExpectLowPrice)

  25: {

  26:       Product product;

  27:       PricingManager* fakeManager = FAKE(PricingManager);

  28:       WHEN_CALLED(fakeManager->isOnSale()).Return(true);

  29:       ASSERT_EQ(5, product.GetPrice(fakeManager));

  30: }

At the same time, I found this table containing information about some unit testing frameworks currently available for C++.

Regards,

Angel

One thought on “Unit Testing Frameworks for C++

Leave a Reply

Your email address will not be published. Required fields are marked *