[英]CppUnit leakage
用 valgrind 運行我的回歸測試我有這樣的報告:
==20341== 256 bytes in 1 blocks are indirectly lost in loss record 915 of 919 ==20341== at 0x4A0661C: operator new(unsigned long) (vg_replace_malloc.c:220) ==20341== by 0x7F366FA: std::vector<CppUnit::Test*, std::allocator<CppUnit::Test*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<CppUnit::Test**, std::vector<CppUnit::Test*, std::allocator<CppUnit::Test*> > >, CppUnit::Test* const&) (new_allocator.h:88) ==20341== by 0x7F36496: CppUnit::TestSuite::addTest(CppUnit::Test*) (stl_vector.h:610) ==20341== by 0x585B80: TestVectorAlgebra::addTestsToSuite(CppUnit::TestSuiteBuilderContextBase&) (testvectoralgebra.h:30) ==20341== by 0x586719: TestVectorAlgebra::suite() (testvectoralgebra.h:42) ==20341== by 0x5948C4: CppUnit::TestSuiteFactory<TestVectorAlgebra>::makeTest() (TestSuiteFactory.h:20) ==20341== by 0x7F2C6B0: CppUnit::TestFactoryRegistry::addTestToSuite(CppUnit::TestSuite*) (TestFactoryRegistry.cpp:149) ==20341== by 0x7F2CAD5: CppUnit::TestFactoryRegistry::makeTest() (TestFactoryRegistry.cpp:136) ==20341== by 0x580760: main (testunit.cpp:88)
我想這是因為在主要結束之前沒有刪除添加到套件的測試。
這是我注冊測試的方式:
CppUnit::TextTestRunner::TestRunner runner;
// Get the top level suite from the registry
CppUnit::Test* myTest =
CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
runner.addTest( myTest->findTest("TestVectorAlgebra") );
我如何取消注冊這些測試?
CppUnit 文檔表明runner.addTest
擁有它所提供的任何測試的所有權。 通過給runner.addTest
您MYTEST實例的只是一部分,你沒有提供任何方式為整個MYTEST執行個體上刪除清理。 運行后手動delete
'ing myTest 可能也不起作用,因為runner
也會嘗試刪除它被賦予的myTest
部分。
如果您只對運行特定測試或測試子集感興趣,則應嘗試使用TextRunner::run的testName
參數。
(如果您有時間和興趣,您可能想研究不同的單元測試框架。UnitTest++和Google Test比 CppUnit 更新、更易於使用且功能更強大。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.