BDD
Behavior Driven Development testing framework for the D programming language
Discussion
Home page: https://github.com/workhorsy/BDD
Version
4.0.0
License
Boost Software License - Version 1.0
Examples
import BDD;
int add(int a, int b) {
return a + b;
}
unittest {
describe("math#add",
before(delegate() {
}),
after(delegate() {
}),
it("Should add positive numbers", delegate() {
add(5, 7).shouldEqual(12);
}),
it("Should add negative numbers", delegate() {
add(5, -7).shouldEqual(-2);
})
);
}
-
Declaration
voidshouldEqual(T, U)(Ta, Ub, stringmessage= null, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one value is equal to another value.
Parameters
TaThe value to test.
UbThe value it should be equal to.
stringmessageThe custom
messageto display instead of default.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If values are not equal, will throw an AssertError with expected and actual values.
Examples
// Will throw an exception like "AssertError@example.d(6): <3> expected to equal <5>." int z = 3; z.shouldEqual(5);
-
Declaration
voidshouldNotEqual(T, U)(Ta, Ub, stringmessage= null, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one value is NOT equal to another value.
Parameters
TaThe value to test.
UbThe value it should NOT be equal to.
stringmessageThe custom
messageto display instead of default.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If values are NOT equal, will throw an AssertError with unexpected and actual values.
Examples
// Will throw an exception like "AssertError@example.d(6): <3> expected to NOT equal <3>." int z = 3; z.shouldNotEqual(3);
-
Declaration
voidshouldBeNull(T)(Ta, stringmessage= null, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one value is equal to
null.Parameters
TaThe value that should equal
null.stringmessageThe custom
messageto display instead of default.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If value is NOT
null, will throw an AssertError.Examples
// Will throw an exception like "AssertError@example.d(6): expected to be <null>." string z = "blah"; z.shouldBeNull();
-
Declaration
voidshouldNotBeNull(T)(Ta, stringmessage= null, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one value is NOT equal to
null.Parameters
TaThe value that should NOT equal
null.stringmessageThe custom
messageto display instead of default.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If value is
null, will throw an AssertError.Examples
// Will throw an exception like "AssertError@example.d(6): expected to NOT be <null>." string z = null; z.shouldNotBeNull();
-
Declaration
voidshouldBeIn(T, U)(Tvalue, U[]valid_values, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one
valueis in an array of specified values.Parameters
TvalueThe
valueto test.U[]valid_valuesAn array of valid values.
stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If the
valueis not in the array, will throw an AssertError with thevalueand array values.Examples
// Will throw an exception like "AssertError@example.d(6): <Bobrick> is not in <[Tim, Al]>." "Bobrick".shouldBeIn(["Tim", "Al"]);
-
Declaration
voidshouldNotBeIn(T, U)(Tvalue, U[]valid_values, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one
valueis NOT in an array of specified values.Parameters
TvalueThe
valueto test.U[]valid_valuesAn array of valid values.
stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If the
valueis in the array, will throw an AssertError with thevalueand array values.Examples
// Will throw an exception like "AssertError@example.d(6): <Mark> is in <[Tim, Mark]>." "Mark".shouldNotBeIn(["Tim", "Mark"]);
-
Declaration
voidshouldBeGreater(T, U)(Ta, Ub, stringmessage= null, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one value is greater than another value.
Parameters
TaThe value to test.
UbThe value it should be greater than.
stringmessageThe custom
messageto display instead of default.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If the value is NOT greater, will throw an AssertError with expected and actual values.
Examples
// Will throw an exception like "AssertError@example.d(6): <5> expected to be greater than <10>." 5.shouldBeGreater(10);
-
Declaration
voidshouldBeLess(T, U)(Ta, Ub, stringmessage= null, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one value is less than another value.
Parameters
TaThe value to test.
UbThe value it should be less than.
stringmessageThe custom
messageto display instead of default.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If the value is NOT less, will throw an AssertError with expected and actual values.
Examples
// Will throw an exception like "AssertError@example.d(6): <10> expected to be less than <5>." 10.shouldBeLess(5);
-
Declaration
voidshouldBeGreaterOrEqual(T, U)(Ta, Ub, stringmessage= null, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one value is greater or equal than another value.
Parameters
TaThe value to test.
UbThe value it should be greater or equal than.
stringmessageThe custom
messageto display instead of default.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If the value is NOT greater or equal, will throw an AssertError with expected and actual values.
Examples
// Will throw an exception like "AssertError@example.d(6): <5> expected to be greater or equal to <10>." 5.shouldBeGreaterOrEqual(10);
-
Declaration
voidshouldBeLessOrEqual(T, U)(Ta, Ub, stringmessage= null, stringfile= __FILE__, size_tline= __LINE__);Used to assert that one value is less or equal than another value.
Parameters
TaThe value to test.
UbThe value it should be less or equal than.
stringmessageThe custom
messageto display instead of default.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If the value is NOT less or equal, will throw an AssertError with expected and actual values.
Examples
// Will throw an exception like "AssertError@example.d(6): <10> expected to be less or equal to <5>." 10.shouldBeLessOrEqual(5);
-
Declaration
voidshouldThrow(void delegate()cb, stringfile= __FILE__, size_tline= __LINE__);Used for asserting that a delegate will throw an exception.
Parameters
void delegate()cbThe delegate that is expected to throw the exception.
stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If delegate does NOT throw, will throw an AssertError.
Examples
// Makes sure it throws, but does not check the message shouldThrow(delegate() { throw new Exception("boom!"); }); // Will throw an exception like "AssertError@test/example.d(7): Exception was not thrown. Expected one. shouldThrow(delegate() { });
-
Declaration
voidshouldThrow(stringmessage, void delegate()cb, stringfile= __FILE__, size_tline= __LINE__);Used for asserting that a delegate will throw an exception.
Parameters
void delegate()cbThe delegate that is expected to throw the exception.
stringmessageThe
messagethat is expected to be in the exception. Will not be tested, if it isnull.stringfileThe
filename that the assert failed in. Should be left as default.size_tlineThe
filelinethat the assert failed in. Should be left as default.Throws
If delegate does NOT throw, will throw an AssertError.
Examples
// Makes sure it throws with the message "boom!" shouldThrow("boom!", delegate() { throw new Exception("boom!"); }); // Will throw an exception like "AssertError@test/example.d(7): Exception was not thrown. Expected: boom!" shouldThrow("boom!", delegate() { });
-
Declaration
voiddescribe(stringdescribe_message, ItFunc[]its...);Used to
describethe thing being tested. Contains many 'it' functions to test the thing.Parameters
stringdescribe_messageThe thing that is being described.
ItFunc[]itsAll the 'it' functions that will test the thing.
Examples
describe("example_library#thing_to_test", it("Should NOT fail", delegate() { // test code here }) );
-
Declaration
voiddescribe(stringdescribe_message, BeforeFuncbefore, ItFunc[]its...);Used to
describethe thing being tested. Contains many 'it' functions to test the thing. Also takes a function to runbeforeeach test.Parameters
stringdescribe_messageThe thing that is being described.
BeforeFuncbeforeThe function that will run
beforeeach 'it' function. If thebeforefunction fails, the 'it' function will not be run.ItFunc[]itsAll the 'it' functions that will test the thing.
Examples
describe("example_library#thing_to_test", before(delegate() { // setup code here }), it("Should NOT fail", delegate() { // test code here }) );
-
Declaration
voiddescribe(stringdescribe_message, AfterFuncafter, ItFunc[]its...);Used to
describethe thing being tested. Contains many 'it' functions to test the thing. Also takes a function to runaftereach test.Parameters
stringdescribe_messageThe thing that is being described.
AfterFuncafterThe function that will run
aftereach 'it' function. Will alwasy run, even if the 'before' or 'it' function failed.ItFunc[]itsAll the 'it' functions that will test the thing.
Examples
describe("example_library#thing_to_test", after(delegate() { // tear down code here }), it("Should NOT fail", delegate() { // test code here }) );
-
Declaration
voiddescribe(stringdescribe_message, BeforeFuncbefore, AfterFuncafter, ItFunc[]its...);Used to
describethe thing being tested. Contains many 'it' functions to test the thing. Also takes a function to runbefore, and a function to runaftereach test.Parameters
stringdescribe_messageThe thing that is being described.
BeforeFuncbeforeThe function that will run
beforeeach 'it' function. If thebeforefunction fails, the 'it' function will not be run.AfterFuncafterThe function that will run
aftereach 'it' function. Will alwasy run, even if the 'before' or 'it' function failed.ItFunc[]itsAll the 'it' functions that will test the thing.
Examples
describe("example_library#thing_to_test", before(delegate() { // setup code here }), after(delegate() { // tear down code here }), it("Should NOT fail", delegate() { // test code here }) );
-
Declaration
ItFuncit(stringmessage, void delegate()func, stringfile= __FILE__, size_tline= __LINE__);The
messageshould describe what the test should do.Parameters
stringmessageThe
messageto print when the test fails.void delegate()funcThe delegate to call when running the test.
stringfileThe
filename that the 'it' is located in. Should be left as default.size_tlineThe
filelinethat the 'it' is located at. Should be left as default.Examples
int a = 4; describe("example_library#a", it("Should equal 4", delegate() { a.shouldEqual(4); }), it("Should Not equal 5", delegate() { a.shouldNotEqual(5); }) );
-
Declaration
BeforeFuncbefore(void delegate()func, stringfile= __FILE__, size_tline= __LINE__);The function to call
beforeeach 'it' function.Parameters
void delegate()funcThe function to call
beforerunning each test.stringfileThe
filename that the 'before' is located in. Should be left as default.size_tlineThe
filelinethat the 'before' is located at. Should be left as default.Examples
int a = 4; describe("example_library#a", before(delegate() { a.shouldEqual(4); }), it("Should test more things", delegate() { // }) );
-
Declaration
AfterFuncafter(void delegate()func, stringfile= __FILE__, size_tline= __LINE__);The function to call
aftereach 'it' function.Parameters
void delegate()funcThe function to call
afterrunning each test.stringfileThe
filename that the 'after' is located in. Should be left as default.size_tlineThe
filelinethat the 'after' is located at. Should be left as default.Examples
int a = 4; describe("example_library#a", after(delegate() { a.shouldEqual(4); }), it("Should test more things", delegate() { // }) );