Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

CppUnit

From Wikipedia, the free encyclopedia
Unit testing framework module
CppUnit
Stable release1.15.1 (LibreOffice version)[1] (13 April 2017; 8 years ago (2017-04-13)) [±]
Written inC++
TypeUnit testing tool
LicenseLGPL
Websitefreedesktop.org/wiki/Software/cppunit
Repository

CppUnit is aunit testing framework module for theC++ programming language. It allows unit-testing ofC sources as well as C++ with minimal source modification. It was started around 2000 by Michael Feathers as a C++port ofJUnit for Windows and ported to Unix by Jerome Lacoste.[2] The library is released under theGNU Lesser General Public License. However, unlike JUnit, CppUnit does not rely onannotations (as annotations were not added to C++ untilC++26), and rather creates tests withpreprocessor macros.

The framework runs tests in suites. Test result output is sent to a filter, the most basic being a simple pass or fail count printed out, or more advanced filters allowing XML output compatible withcontinuous integration reporting systems.[3]

The project has beenforked several times.[4][5] Thefreedesktop.org version atGitHub, maintained by Markus Mohrhard of theLibreOffice project (which uses CppUnit heavily), was actively maintained until 2020, and is used inLinux distributions such asDebian,Ubuntu,Gentoo andArch.[6]


Some libraries, such asPOCO C++ Libraries, provide their own APIs to consume the CppUnit library.

Example

[edit]

Consider the following classInteger:

module;exportmoduleorg.wikipedia.examples.Integer;exportnamespaceorg::wikipedia::examples{classInteger{private:intx=0;public:Integer(intx):x{x}{}[[nodiscard]]intadd(inty)noexcept{x+=y;returnx;}[[nodiscard]]intsubtract(inty)noexcept{x-=y;returnx;}}}

It can be tested like so:

module;exportmoduleorg.wikipedia.examples.tests.IntegerTest;import<cppunit/extensions/HelperMacros.h>;importorg.wikipedia.examples.Integer;usingCppUnit::TestFixture;usingorg::wikipedia::examples::Integer;exportnamespaceorg::wikipedia::examples::tests{classIntegerTest:publicTestFixture{private:CPPUNIT_TEST_SUITE(IntegerTest);CPPUNIT_TEST(testAdd);CPPUNIT_TEST(testSubtract);CPPUNIT_TEST_SUITE_END();Integer*i;protected:voidtestAdd(){CPPUNIT_ASSERT_EQUAL(8,i->add(8));// 5 + 3 = 8}voidtestSubtract(){CPPUNIT_ASSERT_EQUAL(3,i->subtract(2));// 5 - 2 = 3}public:voidsetUp()override{i=newInteger(5);}voidtearDown()override{deletei;}}

Then, it can be tested inmain():

import<cppunit/ui/text/TestRunner.h>importorg.wikipedia.examples.tests.IntegerTest;usingCppUnit::TextUi::TestRunner;usingorg::wikipedia::examples::tests::IntegerTest;intmain(intargc,char*argv[]){TestRunnertestRunner;runner.addTest(IntegerTest::suite());runner.run();}

See also

[edit]

Further reading

[edit]
  • Madden, Blake (6 April 2006). "1.7: Using CPPUnit to implement unit testing". In Dickheiser, Mike (ed.).Game Programming Gems 6. Charles River Media.ISBN 1-58450-450-1.

References

[edit]
  1. ^"Commit description".
  2. ^Mohrhard, Markus."CppUnit Documentation". freedesktop.org.
  3. ^Jenkinsplug-in for CppUnit and other Unit Test tools
  4. ^freedesktop.org fork presented as CppUnit v1.13
  5. ^fork presented as CppUnit2; not modified since 2009
  6. ^Mohrhard, Markus (22 October 2013)."cppunit framework".LibreOffice mailing list. Retrieved20 March 2014.

External links

[edit]
OS components
Sound
Graphics
Other
Libraries
Frameworks
Meetings
Applications
Desktop
Mobile
Server
Technologies
Organisations
Retrieved from "https://en.wikipedia.org/w/index.php?title=CppUnit&oldid=1326492833"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp