I'm using C++Test from Parasoft for unit testing C++ code. I came across the following problem. I have a function similar to the next one (pseudocode):
bool LoadFileToMem(const std::string& rStrFileName)
{
if( openfile(rStrFileName) == successfull )
{
if( get_file_size() == successfull )
{
if( read_entire_file_to_buffer() == successfull )
{
return true;
}
return false;
}
return false;
}
return false;
}
My questions in this case are:
Should I use stubs for file system functions? Or should I include specific sample test files for running the unit tests?
In my case std::fstream class is used for file input.
Has anyone better suggestions? (Best if done in C++Test but not mandatory).
I would go for short sample test files. They can be checked into source control along with the test code. The reason I would do it is that the intent of your function is to load a file, so this is what you should be testing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With