Bonjour tout le monde!
Je débute avec CxxTest. J'essaye de faire des tests unitaires pour la classe suivante:
include/Bindon.h
src/Bindon.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #ifndef BIDON_H_ #define BIDON_H_ namespace test { class Bidon { private: int m_value; public: Bidon(int value=0); virtual ~Bidon(); int getValue() const; void setValue(int value); }; } /* namespace test */ #endif /* BIDON_H_ */
Mon test unitaire:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #include "../include/Bidon.h" namespace test { Bidon::Bidon(int value) : m_value(value) { } Bidon::~Bidon() { } int Bidon::getValue() const { return m_value; } void Bidon::setValue(int value) { m_value = value; } }
include/TestUnitBidon.h
J'essaye de le compiler avec CMake avec le fichier suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #ifndef TESTUNITBIDON_H_ #define TESTUNITBIDON_H_ #include <cxxtest/TestSuite.h> #include "Bidon.h" class TestUnitBidon : public CxxTest::TestSuite { public: void testGetValue() { test::Bidon bidon(10); TS_ASSERT_EQUALS(bidon.getValue(), 10); } void testSetValue() { test::Bidon bidon; TS_ASSERT_EQUALS(bidon.getValue(), 0); bidon.setValue(10); TS_ASSERT_EQUALS(bidon.getValue(), 0); } }; #endif /*TESTUNITBIDON_H_*/
CMakeLists.txt
L'exécutable testExe compile et fonctionne parfaitement avec le main suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 cmake_minimum_required(VERSION 2.8) project(test_unit) FIND_PACKAGE(CxxTest REQUIRED) # Use Python interpreter SET(CXXTEST_USE_PYTHON 1) include_directories(${CMAKE_SOURCE_DIR}/include . ${CXXTEST_INCLUDE_DIR}) file(GLOB_RECURSE src_files "${CMAKE_SOURCE_DIR}/src/*.cpp") file(GLOB_RECURSE test_files ${CMAKE_SOURCE_DIR}/include/TestUnitBidon.h) add_executable(testExe ${src_files}) ENABLE_TESTING() CXXTEST_ADD_TEST(unit-test test/unit/cxxtest/src/unit-test.cpp ${test_files}) add_executable(test-unit test/unit/cxxtest/src/unit-test.cpp src/Bidon.cpp)
src/main.cpp
Malheureusement, quand je tente de compiler le test unitaire j'ai des problèmes au niveau de l'édition de liens:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 #include <cstdlib> #include "Bidon.h" int main(int argc, char **argv) { test::Bidon bidon; bidon.getValue(); bidon.setValue(10); return EXIT_SUCCESS; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 ~/test_unit] make [ 14%] [ 28%] Scanning dependencies of target testExe Generating test/unit/cxxtest/src/unit-test.cpp Generating test/unit/cxxtest/src/unit-test.cpp [ 57%] [ 57%] Building CXX object CMakeFiles/testExe.dir/src/Bidon.cpp.o Building CXX object CMakeFiles/testExe.dir/src/main.cpp.o Linking CXX executable testExe [ 57%] Built target testExe Scanning dependencies of target unit-test Scanning dependencies of target test-unit [ 71%] [100%] [100%] Building CXX object CMakeFiles/test-unit.dir/src/Bidon.cpp.o Building CXX object CMakeFiles/test-unit.dir/test/unit/cxxtest/src/unit-test.cpp.o Building CXX object CMakeFiles/unit-test.dir/test/unit/cxxtest/src/unit-test.cpp.o Linking CXX executable unit-test Linking CXX executable test-unit Undefined symbols for architecture x86_64: "test::Bidon::Bidon(int)", referenced from: TestUnitBidon::testGetValue() in unit-test.cpp.o TestUnitBidon::testSetValue() in unit-test.cpp.o "test::Bidon::getValue() const", referenced from: TestUnitBidon::testGetValue() in unit-test.cpp.o TestUnitBidon::testSetValue() in unit-test.cpp.o "test::Bidon::~Bidon()", referenced from: TestUnitBidon::testGetValue() in unit-test.cpp.o TestUnitBidon::testSetValue() in unit-test.cpp.o "test::Bidon::setValue(int)", referenced from: TestUnitBidon::testSetValue() in unit-test.cpp.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make[2]: *** [unit-test] Error 1 make[1]: *** [CMakeFiles/unit-test.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [100%] Built target test-unit make: *** [all] Error 2
J'ai fait cette compilation sous Mac OS X Lion avec g++ (i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)) ainsi que sous Ubuntu 10.04 avec g++ (4.4.3) sans aucun changement.
Je me doute que je ne compile pas correctement, mais je ne vois pas mon erreur.
Si vous avez des idées...
Merci d'avance!
PS: Peut-on cacher les balises CODE pour que sauver un peu de place?
Partager