Netbeans Cpp编译和运行项目,但不能使用cppunit进行测试
Netbeans Cpp compiles and runs project, but not test with cppunit
我有一个c++项目使用库,如wiiringpi和MySQL连接器。我的常规项目在运行时可以正常编译。当我尝试测试其中一个测试时,它无法构建项目。
输出如下:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/nick/NetBeansProjects/utest'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/utest
make[2]: Entering directory '/home/nick/NetBeansProjects/utest'
make[2]: 'dist/Debug/GNU-Linux/utest' is up to date.
make[2]: Leaving directory '/home/nick/NetBeansProjects/utest'
make[1]: Leaving directory '/home/nick/NetBeansProjects/utest'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-tests-conf
make[1]: Entering directory '/home/nick/NetBeansProjects/utest'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/utest
make[2]: Entering directory '/home/nick/NetBeansProjects/utest'
make[2]: 'dist/Debug/GNU-Linux/utest' is up to date.
make[2]: Leaving directory '/home/nick/NetBeansProjects/utest'
mkdir -p build/Debug/GNU-Linux/tests/TestFiles
g++ -lmysqlcppconn -lwiringPi -o build/Debug/GNU-Linux/tests/TestFiles/f1 build/Debug/GNU-Linux/tests/tests/ConfigParserRunner.o build/Debug/GNU-Linux/tests/tests/ConfigParserTest.o build/Debug/GNU-Linux/main_nomain.o build/Debug/GNU-Linux/src/ConfigFactory_nomain.o build/Debug/GNU-Linux/src/DatabaseAdapter_nomain.o build/Debug/GNU-Linux/src/MatrixControl_nomain.o build/Debug/GNU-Linux/src/ModuleEntity_nomain.o build/Debug/GNU-Linux/src/ModuleServer_nomain.o build/Debug/GNU-Linux/src/SerialDriver_nomain.o build/Debug/GNU-Linux/src/StorageManagement_nomain.o -Llib/cpputest-3.8/lib -L/usr/lib/mysql -L/usr/lib/x86_64-linux-gnu -L/usr/include/cppconn -L/usr/include/cppunit -lCppUTest -lCppUTestExt `cppunit-config --libs`
build/Debug/GNU-Linux/src/DatabaseAdapter_nomain.o: In function `DatabaseAdapter::DatabaseAdapter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/nick/NetBeansProjects/utest/src/DatabaseAdapter.cxx:8: undefined reference to `get_driver_instance'
build/Debug/GNU-Linux/src/DatabaseAdapter_nomain.o: In function `DatabaseAdapter::addProduct(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, productData, int)':
/home/nick/NetBeansProjects/utest/src/DatabaseAdapter.cxx:27: undefined reference to `get_driver_instance'
build/Debug/GNU-Linux/src/DatabaseAdapter_nomain.o: In function `DatabaseAdapter::getEntriesByModule(int)':
/home/nick/NetBeansProjects/utest/src/DatabaseAdapter.cxx:66: undefined reference to `get_driver_instance'
build/Debug/GNU-Linux/src/MatrixControl_nomain.o: In function `MatrixControl::MatrixControl(ModuleServer*)':
/home/nick/NetBeansProjects/utest/src/MatrixControl.cpp:23: undefined reference to `wiringPiSetup'
build/Debug/GNU-Linux/src/SerialDriver_nomain.o: In function `SerialDriver::SerialDriver()':
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:18: undefined reference to `pinMode'
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:19: undefined reference to `pinMode'
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:20: undefined reference to `pinMode'
build/Debug/GNU-Linux/src/SerialDriver_nomain.o: In function `SerialDriver::sendShiftData(unsigned char)':
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:28: undefined reference to `shiftOut'
build/Debug/GNU-Linux/src/SerialDriver_nomain.o: In function `SerialDriver::setLatch(bool)':
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:33: undefined reference to `digitalWrite'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:146: recipe for target 'build/Debug/GNU-Linux/tests/TestFiles/f1' failed
make[1]: *** [build/Debug/GNU-Linux/tests/TestFiles/f1] Error 1
make[1]: Leaving directory '/home/nick/NetBeansProjects/utest'
nbproject/Makefile-impl.mk:67: recipe for target '.build-tests-impl' failed
make: *** [.build-tests-impl] Error 2
BUILD TESTS FAILED (exit value 2, total time: 584ms)
在实现DatabaseAdapter &SerialDriver类。
我在链接器中添加了库选项,在我的主要项目属性中添加了额外选项,如下所示:
-lCppUTest -lCppUTestExt -lwiringPi -lpthread -lmysqlclient -lmysqlcppconn -lcppunit -ldl
我做了什么错误的链接?
编辑:我尝试测试的测试没有使用任何失败的类。
解决方案是将依赖项作为选项添加到库文件夹中。我在链接器中添加了- lwiiringpi和-lmysqlcppconn
相关文章:
- 尽管测试成功,CppUnit测试核心仍被丢弃.为什么
- 在 CppUnit 中测试中止断言失败
- CppUnit 测试与 Qt 5.9 一起挂起
- cppUnit:针对多个测试方法执行一次的设置函数
- CPPUNIT:我们真的每个测试需要一个功能吗?
- 如何启动CPPUNIT测试
- 使用单元测试 (cppunit) 中另一个文件中定义的结构时出错
- CPPUNIT创建一个简单的测试
- 了解cppUnit测试
- CPPUNIT:公共基础测试
- 在谷歌测试或cppunit下移动参数化测试
- Netbeans Cpp编译和运行项目,但不能使用cppunit进行测试
- 如何使用cppunit显示测试方法名称
- 如何编写CPPUnit测试
- 在现有项目中创建CPPUnit测试需要哪些.cpp和.h文件
- CppUnit,很简单的测试代码崩溃了,为什么
- 第一个CppUnit测试:对CppUnit::SourceLine::SourceLine的未定义引用
- cppUnit在启动每个单元测试时是否使用fork() ?
- 用CppUnit测试静态函数
- 单元测试vc++ MFC应用程序使用CPPUNIT或GTEST