I tried to follow this guide but it's not working for me: http://codelite.org/LiteEditor/UnitTestPP
I am on Linux Mint 17.3 xfce, running CodeLite version 9.1.0.
First I created a project "DummyClass." I did this by doing the following:
1) Right click on the workspace.
2) Click "Create New Project"
3) Under Console, I select "Simple executable (g++)"
4) For Project name I type DummyClass
5) I check the box that says "Create the project under a separate directory"
6) Click next/next (accept the defaults: Compiler: GCC and Debugger: GNU gdb debugger)
Inside DummyClass I create a new class named IntNum. I do this by right clicking on the virtual folder named "src" inside the DummyClass project. It is the only virtual folder in the project. I don't see the "include" virtual folder in the project like it shows in the guide.
Next I create a new project called "DummyClass_test" by doing the following:
1) Right click on the workspace.
2) Click "Create New Project"
3) Under Console, I select "UnitTest++"
4) For Project name I type DummyClass_test
5) I check the box that says "Create the project under a separate directory"
6) Click next/next (accept the defaults: Compiler: GCC and Debugger: GNU gdb debugger)
I end up with the following:
In DummyClass_test/src/main.cpp, I add a sanity check to make sure I can compile and link UnitTest++ correctly:
DummyClass_test/src/main.cpp:
Code: Select all
#include <unittest++/UnitTest++.h>
TEST( Sanity )
{
CHECK_EQUAL( 1, 1 );
}
// run all tests
int main(int argc, char **argv)
{
return UnitTest::RunAllTests();
}
However, then I try to add a test for IntNum in DummyClass.
First I try adding the include directive:
Code: Select all
#include "DummyClass/IntNum.h"
TEST( Sanity )
{
CHECK_EQUAL( 1, 1 );
}
// run all tests
int main(int argc, char **argv)
{
return UnitTest::RunAllTests();
}
Code: Select all
/bin/sh -c '/usr/bin/make -j4 -e -f Makefile'
----------Building project:[ DummyClass_test - Debug ]----------
make[1]: Entering directory `/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test'
/usr/bin/g++ -c "/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test/main.cpp" -g -o Debug/main.cpp.o -I. -I/src -I.
/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test/main.cpp:58:31: fatal error: DummyClass/IntNum.h: No such file or directory
#include "DummyClass/IntNum.h"
^
compilation terminated.
make[1]: *** [Debug/main.cpp.o] Error 1
make[1]: Leaving directory `/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test'
make: *** [All] Error 2
====2 errors, 0 warnings====
Code: Select all
#include "../DummyClass/IntNum.h"
TEST( Sanity )
{
CHECK_EQUAL( 1, 1 );
}
// run all tests
int main(int argc, char **argv)
{
return UnitTest::RunAllTests();
}
Code: Select all
#include "../DummyClass/IntNum.h"
TEST( Sanity )
{
IntNum intNum;
CHECK_EQUAL( 1, 1 );
}
// run all tests
int main(int argc, char **argv)
{
return UnitTest::RunAllTests();
}
Code: Select all
/bin/sh -c '/usr/bin/make -j4 -e -f Makefile'
----------Building project:[ DummyClass_test - Debug ]----------
make[1]: Entering directory `/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test'
/usr/bin/g++ -c "/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test/main.cpp" -g -o Debug/main.cpp.o -I. -I/src -I.
/usr/bin/g++ -o Debug/DummyClass_test @"DummyClass_test.txt" -L. -L/Debug -lUnitTest++
Debug/main.cpp.o: In function `TestSanity::RunImpl() const':
/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test/main.cpp:62: undefined reference to `IntNum::IntNum()'
/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test/main.cpp:63: undefined reference to `IntNum::~IntNum()'
/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test/main.cpp:63: undefined reference to `IntNum::~IntNum()'
collect2: error: ld returned 1 exit status
make[1]: *** [Debug/DummyClass_test] Error 1
make[1]: Leaving directory `/home/qk/programming_practice/CodeLiteUnitTest/DummyClass_test'
make: *** [All] Error 2
====4 errors, 0 warnings====
I tried doing what it says in the CodeLite UnitTest++ guide (right click -> UnitTest++ -> Create tests for class), but all that does is create two empty test cases in DummyClass_test/src/main.cpp:
Code: Select all
#include "../DummyClass/IntNum.h"
TEST( Sanity )
{
IntNum intNum;
CHECK_EQUAL( 1, 1 );
}
// run all tests
int main(int argc, char **argv)
{
return UnitTest::RunAllTests();
}
TEST(TestIntNum_IntNum)
{
}
TEST(TestIntNum_TildaIntNum)
{
}
What am I doing wrong?
I can get UnitTest++ semi-working by putting the contents of DummyClass_test/src/main.cpp into a renamed file (i.e. DummyClass/src/DummyClass_test.cpp) in the DummyClass project, but then I have to rename the main() function in DummyClass/src/main.cpp to avoid the multiple definition of main() error. So if I want to run the DummyClass's main(), I rename the mangled main() in DummyClass/src/main.cpp back to main(), and rename the main() in DummyClass/src/DummyClass_test.cpp to something else (like main_()), then recompile, and vice versa. So to run either the app main() or the test main() I have manually rename the main functions to avoid the conflict. This really seems like the wrong way to do it. I'd like to do it the proper way, but I don't know what I'm doing wrong. Can anyone help?