I have a project that has hundreds of XML files that contain data to be processed by an application. I would like to create a cppunit framework around them. My initial approach was to create a test that executed all the 'success' data and another one that executed all the 'failure' data (testing for proper handling of error conditions). The problem with this approach is that the test would error out on the first file that had a problem. I would like a solution where I could process each file as a CPPUNIT Test/Feature independently, so when one data file has an error, the rest would continue to process. Ideally, this would be done dynamically, so you could add/remove test data files without making changes to the code.
Any suggestions on a solution?
Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
// for each filename in this->directory
// suite.add(XMLTest(filename));
return suite;
}
---------------------------------------------
I have left out a few of the details. The contstructors should be trivial to implement. The comments in XMLSuite::suite() give pseudocode for how to dynamically create your test cases. The exact implementation is dependent on the development environment and operating system.
Note that you won't have to recompile this test to test a new file. Just place it in the directory specified in the XMLSuite constructor. You can also take this up another level and create a suite for specific directories. This would allow you to organize the XML files if there are a lot of them. You could also create a text file with a list of directories to read in to create several XMLSuite objects.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a project that has hundreds of XML files that contain data to be processed by an application. I would like to create a cppunit framework around them. My initial approach was to create a test that executed all the 'success' data and another one that executed all the 'failure' data (testing for proper handling of error conditions). The problem with this approach is that the test would error out on the first file that had a problem. I would like a solution where I could process each file as a CPPUNIT Test/Feature independently, so when one data file has an error, the rest would continue to process. Ideally, this would be done dynamically, so you could add/remove test data files without making changes to the code.
Any suggestions on a solution?
Thanks in advance.
I apologize if this response is a little delayed. I would suggest doing something similar to the following:
// XMLTest.h
class XMLTest : TestCase {
public:
XMLTest(std::string filename);
// various testXxx() methods for a single file
private:
std::string filename;
};
// XMLTest.cpp
// contains implementations of XMLTest::testXxx() methods
-------------------------------------
// XMLSuite.h
class XMLSuite : TestSuite {
public:
XMLSuite(std::string directory);
static TestCase suite();
private:
std::string directory;
}
// XMLSuite.cpp
static TestCase XMLSuite::suite() {
TestCase suite;
// for each filename in this->directory
// suite.add(XMLTest(filename));
return suite;
}
---------------------------------------------
I have left out a few of the details. The contstructors should be trivial to implement. The comments in XMLSuite::suite() give pseudocode for how to dynamically create your test cases. The exact implementation is dependent on the development environment and operating system.
Note that you won't have to recompile this test to test a new file. Just place it in the directory specified in the XMLSuite constructor. You can also take this up another level and create a suite for specific directories. This would allow you to organize the XML files if there are a lot of them. You could also create a text file with a list of directories to read in to create several XMLSuite objects.