I have a problem with testing class with member variable which is not dependent on me. I mean the class contain a variable that is include from other file. And this class throwing error in constructor(no matter why). And then I have a function that uses this variable. So how should I test this class?
// ** classForMe.h can't modify **
class ClassForMe
{
public:
ClassForMe(){
// not relevant what should be here but throw error in this case
throw std::runtime_error("");
}
int getData()const {return data;}
...
private:
int data;
};
other file which contain my class
// C.hpp
#include <classForMe.h>
class C
{
public:
C():classForMe{}{}
void save(){
//some code here, but i need data from ClassForMe
int i = classForMe.getData();
...
}
private:
ClassForMe classForMe;
};
If I not clear explained my problem and someone thinking "why you want to testing code which throwing error". This code working well, but not in my platform. For me it throwing error so is posible write test for this class e.g. i emulate that classForMe is construt well and contain some value? And then this value will be used in test of method void save()?
#include <gtest/gtest.h>
#include "C.hpp"
class C_test : public ::testing::Test
{
... ??
};