CppUnit is a C++ port of the JUnit Java testing framework, which was developed by Erich Gamma and Kent Beck. If you have existing CppUnit tests, you can run them using C++test and take advantage of the extended testing capabilities of the C++test infrastructure.

CppUnit tests can be run in C++test just like the other unit tests we have created in earlier exercises. We recommend that you keep the CppUnit tests in a separate directory at or above the C++test tests directory in the project and create a configuration to access them.

Create the "Run CppUnit Tests (Project Scope)" Test Configuration

  1. Open the Test Configurations window and duplicate the User-defined> Run Unit Tests (Project Scope) created in Exercise 5.
  2. Open the Execution> General tab and set Test suite file search patterns(*) to ${project_loc}/CppUnit/* (this points to the CppUnit directory added).





  3. Rename the configuration Run CppUnit Tests (Project Scope).
  4. Click Apply and Close.
  5. Open the Quality Tasks view and click the double Xs in the panel menu to clear the contents of the tab before the running the CppUnit test configuration. Repeat for the Coverage view.





  6. Select the ATM project or other scope that the CppUnit tests were written for and run the Run CppUnit Tests (Project Scope) configuration. The tests should run successfully, but flag an assertion error.
  7. Expand Fix Unit Test Problems in the Quality Tasks view and double-click on the assertion failure to view the source of the problem.



    The CppUnit test is expecting a non-zero return from the test call.
  8. Open Bank.cxx and go to the getAccount function.



    The function always returns NULL, but the comments indicate that userAccount should be returned if the password is correct. 
  9. Modify the code to return userAccount to fix the problem.
  10. Select ATM> CppUnit> BankTestCase> testGetAccount and rerun the tests to verify the fix.
  • No labels