Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML #include <boost/test/minimal.hpp> Int add( int i, int j ) { return i+j; } Int test_main( int , char *[ ] ) // note the name! { BOOST_CHECK( add( 2 , 2 ) == 4 ); // #1 continues on error BOOST_REQUIRE( add( 2 , 2 ) == 4 ); // #2 throws on error if ( add( 2 , 2 ) != 4 ) BOOST_ERROR( "Ouch..." ); // #3 continues on error if ( add( 2 , 2 ) != 4 ) BOOST_FAIL( "Ouch..." ); // #4 throws on error if ( add( 2 , 2 ) != 4 ) throw "Oops..." ; // #5 throws on error return add( 2 , 2 ) == 4 ? 0 : 1 ; // #6 returns error code }
Copy Source | Copy HTML
- class MyTest : public CxxTest :: TestSuite
- {
- public :
- void testMethod ( void )
- {
- TS_ASSERT ( 1 + 1 > 1 );
- TS_ASSERT_EQUALS ( 1 + 1 , 2 );
- }
- };
Copy Source | Copy HTML
- # perl cxxtestgen.pl --error-printer -o runner.cpp MyTest.h
- MyTest.h - the test we wrote
- runner.cpp - output file (the main () function will be created in it)
- cxxtestgen.pl or cxxtestgen.py - preprocessor
Copy Source | Copy HTML
- # g ++ -o runner runner.cpp
Copy Source | Copy HTML
- # ./runner
- Running 1 test.OK!
Copy Source | Copy HTML
- # ./runner
- Running 2 tests.
- MyTest.h: 15: Expected (2 * 2 == 5), found (4! = 5)
- Failed 1 of 2 tests
- Success rate: 50%
Source: https://habr.com/ru/post/69160/
All Articles