Examples
Examples
calculator_test.hpp
#include "goldilocks/goldilocks" class Calculator; // imagine the class has been defined class TestAdd : public Test { protected: Calculator* calc; public: TestAdd() : Test("add", "Test adding two numbers."), calc(nullptr) {} bool pre() { this->calc = new Calculator(); return (this->calc != nullptr); } void prefail() { // No calculator allocated, do nothing. } bool run() { REQUIRE(Expect<That::IsEqual>(this->calc->add(25, 75), 100); REQUIRE(Expect<That::IsEqual, Should::Fail>(this->calc->add(25, 50), 100)); } void post() { delete this->calc; this->calc = nullptr; } } class SuiteCalculator : public Suite { public: SuiteCalculator() : Suite("calculator", "Tests for Calculator object.") {} void load_tests() { register(new TestAdd()); } }
In Goldilocks Shell:
>> list calculator [suite] >> run calculator Running calculator [Suite] Running calculator:add 100 == 100 75 == 100 (Should Fail) PASS >> list calculator :add >> run calculator:add Running calculator:add [Behavior Test] 100 == 100 75 == 100 (Should Fail) PASS: 1 of 1 >> run calculator:add 100 Running calculator:add [Behavior Test] Passes: 100 (Output of successful passes hidden.) PASS: 100 of 100 >> help calculator calculator [suite] Tests for Calculator object. :add [Behavior Test] >> help calculator:add calculator:add [Behavior Test] Test adding two numbers. >> exit
- Last Author
- jcmcdonald
- Last Edited
- Jul 10 2020, 12:18 PM