Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancalhoun committed Dec 11, 2015
1 parent 62c287c commit c04a74b
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,68 @@ A fork of http://www.freedesktop.org/wiki/Software/cppunit.
CppUnit is the C++ port of the famous JUnit framework for unit
testing.

## Create your test runner
```c++
#include "cppunit/TestResultCollector.h"
#include "cppunit/ui/text/TestRunner.h"

int main(int argc, const char* argv[])
{
CppUnit::TextUi::TestRunner runner;

runner.addTest(MyTestClass::suite());
runner.run();

return runner.result().testFailures();
}
```
## Define each text suite
```c++
#include "cppunit/CppUnit.h"
class MyTestClass : public CppUnit::TestFixture
{
public:
void testSomething();
static CppUnit::Test* suite()
{
CPPUNIT_DEFINE_SUITE(suite, MyTestClass);
CPPUNIT_ADD_TEST(suite, testSomething);
return suite;
}
};
```
## Make assertions
```c++
void MyTestClass::testSomething()
{
int x = 42;
assert_true(x > 0 && x < 100);
assert_false(x < 0);
assert_equal(42, x);
}
```

## Available asserts
```c++
void assert_true(condition);
void assert_false(condition);
void assert_equal(expected, actual);
void assert_less(expected, actual);
void assert_less_equal(expected, actual);
void assert_greater(expected, actual);
void assert_greater_equal(expected, actual);
void assert_doubles_equal(expected, actual, tolerance);
void assert_throw(expected_type, expression);
void assert_no_throw(expression);
```
Each of the above asserts may take an additional (last) parameter, an assert failure message.
For instance:
```c++
assert_true(foo, "better check the database again");
assert_greater_equal(0, timestamp, "need to update the license file");
```

0 comments on commit c04a74b

Please sign in to comment.