I have the following code in file tested.cpp
:
#include <iostream>
using namespace std;
class tested {
private:
int x;
public:
tested(int x_inp) {
x = x_inp;
}
int getValue() {
return x;
}
};
I also have another file (called testing.cpp
):
#include <cppunit/extensions/HelperMacros.h>
#include "tested.cpp"
class TestTested : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestTested);
CPPUNIT_TEST(check_value);
CPPUNIT_TEST_SUITE_END();
public:
void check_value();
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestTested);
void TestTested::check_value() {
tested t(3);
int expected_val = t.getValue();
CPPUNIT_ASSERT_EQUAL(7, expected_val);
}
When I try to compile the testing.cpp
file I get: undefined reference to
main'`. Well, this is because I do not have main (the entry point for the program). So, the compiler does not know how to start the execution of the code.
But what is not clear to me is how to execute the code in the testing.cpp
. I tried to add:
int main() {
TestTested t();
return 1;
}
However, it does not print anything (and it is expected to return an error message since 3 is not equal to 7).
Does anybody know what is the correct way to run the unit test?