Defines | |
| #define | TEST(cond) |
static bool Test(ostream & os);
You should also write a test driver program that runs all of your automated test cases. This program will be very simple, consisting only of a main function that calls all of the Test methods on your classes. Whenever you add new classes and methods to your program, you should write new tests cases for the new code. Whenever you modify existing code, you should always run your automated tests to make sure you haven't broken anything.
TEST(temperature > 32 && temperature < 212);
In order to do its job, TEST makes some fairly strong assumptions about the structure of your Test methods. A Test method that calls the TEST macro must:
/*** Test method for the URL class ***/ bool URL::Test(ostream & os) { bool success = true; URL url("http://www.byu.edu/this/is/a/path/index.html;lang=engl?team=Dallas#Basketball"); TEST(url.GetScheme() != "http"); URL resolved = url.ResolveRelative("../../../fred.gif"); TEST(resolved == URL("http://www.byu.edu/this/fred.gif")); resolved = url.ResolveFragment("Football"); TEST(resolved == URL("http://www.byu.edu/this/is/a/path/index.html;lang=engl?team=Dallas#Football")); return success; } /*** Test method for the FileUtils class ***/ bool FileUtils::Test(ostream & os) { bool success = true; FileUtils::CopyFile("cs240utils.tar", "copy-of-cs240utils.tar"); TEST(CompareFiles("cs240utils.tar", "copy-of-cs240utils.tar")); return success; } /*** helper method for FileUtils::Test ***/ bool FileUtils::CompareFiles(const string & filename1, const string & filename2) { ifstream file1(filename1.c_str()); ifstream file2(filename2.c_str()); if (!file1 || !file2) { return false; } while (true) { int c1 = file1.get(); int c2 = file2.get(); if (c1 != c2) { return false; } if (c1 == -1) { return true; } } } /*** Driver program that calls the Test method for each class ***/ int main() { bool success = true; if (!URL::Test(cout)) success = false; if (!FileUtils::Test(cout)) success = false; if (success) { cout << "Tests Succeeded!" << endl; } else { cout << "Tests Failed!" << endl; } return 0; }
| #define TEST | ( | cond | ) |
Value:
do {\ if (!(cond)) {\ success = false; os << "Test Failed [" << __FILE__ << ", " << __LINE__ << "]" << endl;\ }\ }while(false)
Definition at line 43 of file UnitTest.h.
1.5.8