Cpptest Cheatsheet

ADVERTISEMENT

CPPTEST CHEATSHEET
#include
"cpptest.h"
Test::Suite
Suite ()
virtual
~Suite ()
void
add (std::auto_ptr< Suite > suite)
bool
run (Output &output,
bool
cont_after_fail=true)
Test::CompilerOutput
enum
Format { Generic, BCC, GCC, MSVC }
CompilerOutput (Format format=Generic, std::ostream &stream=std::cout)
CompilerOutput
(const
std::string &format, std::ostream &stream=std::cout)
virtual void
assertment
(const
Source &s)
Test::TextOutput
enum
Mode { Terse, Verbose }
TextOutput (Mode mode, std::ostream &stream=std::cout)
virtual void
finished
(int
tests,
const
Time &time)
virtual void
suite_start
(int
tests,
const
std::string &name)
virtual void
suite_end
(int
tests,
const
std::string &name,
const
Time &time)
virtual void
test_end
(const
std::string &name,
bool
ok,
const
Time &time)
virtual void
assertment
(const
Source &s)
Test::HtmlOutput
void
generate (std::ostream &os,
bool
incl_ok_tests=true,
const
std::string &name="")
Example Fixture
Example Suite
class
SomeTestSuite:
public
Test::Suite
// ... with many tests
{
class
TestSuite1:
public
Test::Suite { };
public:
// ... with many tests
SomeTestSuite()
class
TestSuite2:
public
Test::Suite { };
{
// ... with many tests
TEST_ADD(SomeTestSuite::test1)
class
TestSuite3:
public
Test::Suite { };
TEST_ADD(SomeTestSuite::test2)
}
bool
run_tests()
protected:
{
// setup resources...
Test::Suite ts;
virtual void
setup()
{}
ts.add(auto_ptr<Test::Suite>(new
TestSuite1));
// remove resources...
ts.add(auto_ptr<Test::Suite>(new
TestSuite2));
virtual void
tear_down() {}
ts.add(auto_ptr<Test::Suite>(new
TestSuite3));
private:
// use common resources...
Test::TextOutput output(Test::TextOutput::Verbose);
void
test1() {}
return
ts.run(output);
 
// use common resources...
}
void
test2() {}
};
General asserts
Exception asserts
TEST_FAIL(msg)
TEST_THROWS(expr, x)
TEST_THROWS_MSG(expr, x, msg)
Comparision asserts
TEST_THROWS_ANYTHING(expr)
TEST_THROWS_ANYTHING_MSG(expr, msg)
TEST_ASSERT(expr)
TEST_THROWS_NOTHING(expr)
TEST_ASSERT_MSG(expr, msg)
TEST_THROWS_NOTHING_MSG(expr, msg)
TEST_ASSERT_DELTA(a, b, delta)
TEST_ASSERT_DELTA_MSG(a, b, delta, msg)

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go