- In the Test Case Explorer, right-click the tests directory and choose Add New> Test Suite.
Set the Test suite name and add a usergenerated directory in the Test suite location:
- Click Finish.
- Add a data source to the test suite:
- In the Test Case Explorer, right-click the ATM project, then choose Add New> Data Source.
- Select Table and click Finish.
- Enter a Name.
- Enable the First row specifies column names option.
- Double-click the fields and enter the followiing values
- A header: password
- A2: a1
- A3: really_long_password
- A4: foo
- B header: result
- B2: a1
- B3: really_long_password
B4: goo.
- Save the data source file.
- In the Test Case Explorer, right-click TestSuite_Account_DS and choose Add New> Test Case using Wizard.
- Specify the test case:
- In the first page of the wizard, specify the File value by clicking Browse and navigating to Account.cxx. For Function, select void Account::setPassword(const char *) from the pull down menu.
- Click Next.
- Check Use data source and use the pull down menu to select the TestPasswordDS data source created earlier.
- For Input> Arguments> password, double-click on NULL and use the pull down menu to select {password}.
- Click Finish.
- Edit test_setPassword test case:
- In the Test Case Explorer, double-click the test_setPassword test case to open the test suite.
- Add #include "Account.hxx" to the top of the test suite.
Remove the three post-condition checks at the end of the test_setPassword test case and replace with
CPPTEST_ASSERT_CSTR_EQUAL(CPPTEST_DS_GET_CSTR("result")
,_cpptest_TestObject.getPassword());
Save the changes to the test suite.
- Run the tests by selecting test_setPassword in the Test Case Explorer, then choosing Parasoft> Test Using> User-Defined> Run Unit Tests (Project Scope). The Test Progress Tab will report 3 tests passed and 1 assertion failures.
- Open the Quality Tasks view and expand Fix Unit Test Problems to review the assertion failure that we built into the Data Source table.
- Fix the result in the table and rerun the test to observe the correction.
You can add additional tests by simply adding or modifying rows in the data source.