c++ - Where to put main and what to write there? -


i have 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 have 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 try compile testing.cpp file get: undefined reference tomain'`. well, because not have main (the entry point program). so, compiler not know how start execution of code.

but not clear me how execute code in testing.cpp. tried add:

int main() {         testtested t();         return 1; } 

however, not print (and expected return error message since 3 not equal 7).

does know correct way run unit test?

since writing cppunit test, why not looking @ cppunit doc ? (http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html)

it tells main sould written :

#include <cppunit/ui/text/testrunner.h> #include "exampletestcase.h" #include "complexnumbertest.h"  int main( int argc, char **argv) {   cppunit::textui::testrunner runner;   runner.addtest( exampletestcase::suite() );   runner.addtest( complexnumbertest::suite() );   runner.run();   return 0; }  

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -