BDD
Behavior Driven Development testing framework for the D programming language
Discussion
Home page: https://github.com/workhorsy/BDD
Version
4.1.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
void
shouldEqual
(T, U)(Ta
, Ub
, stringmessage
= null, stringfile
= __FILE__, size_tline
= __LINE__);Used to assert that one value is equal to another value.
Parameters
T
a
The value to test.
U
b
The value it should be equal to.
string
message
The custom
message
to display instead of default.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldNotEqual
(T, U)(Ta
, Ub
, stringmessage
= null, stringfile
= __FILE__, size_tline
= __LINE__);Used to assert that one value is NOT equal to another value.
Parameters
T
a
The value to test.
U
b
The value it should NOT be equal to.
string
message
The custom
message
to display instead of default.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldBeNull
(T)(Ta
, stringmessage
= null, stringfile
= __FILE__, size_tline
= __LINE__);Used to assert that one value is equal to
null
.Parameters
T
a
The value that should equal
null
.string
message
The custom
message
to display instead of default.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldNotBeNull
(T)(Ta
, stringmessage
= null, stringfile
= __FILE__, size_tline
= __LINE__);Used to assert that one value is NOT equal to
null
.Parameters
T
a
The value that should NOT equal
null
.string
message
The custom
message
to display instead of default.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldBeIn
(T, U)(Tvalue
, U[]valid_values
, stringfile
= __FILE__, size_tline
= __LINE__);Used to assert that one
value
is in an array of specified values.Parameters
T
value
The
value
to test.U[]
valid_values
An array of valid values.
string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that the assert failed in. Should be left as default.Throws
If the
value
is not in the array, will throw an AssertError with thevalue
and array values.Examples
// Will throw an exception like "AssertError@example.d(6): <Bobrick> is not in <[Tim, Al]>." "Bobrick".shouldBeIn(["Tim", "Al"]);
-
Declaration
void
shouldNotBeIn
(T, U)(Tvalue
, U[]valid_values
, stringfile
= __FILE__, size_tline
= __LINE__);Used to assert that one
value
is NOT in an array of specified values.Parameters
T
value
The
value
to test.U[]
valid_values
An array of valid values.
string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that the assert failed in. Should be left as default.Throws
If the
value
is in the array, will throw an AssertError with thevalue
and array values.Examples
// Will throw an exception like "AssertError@example.d(6): <Mark> is in <[Tim, Mark]>." "Mark".shouldNotBeIn(["Tim", "Mark"]);
-
Declaration
void
shouldBeGreater
(T, U)(Ta
, Ub
, stringmessage
= null, stringfile
= __FILE__, size_tline
= __LINE__);Used to assert that one value is greater than another value.
Parameters
T
a
The value to test.
U
b
The value it should be greater than.
string
message
The custom
message
to display instead of default.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldBeLess
(T, U)(Ta
, Ub
, stringmessage
= null, stringfile
= __FILE__, size_tline
= __LINE__);Used to assert that one value is less than another value.
Parameters
T
a
The value to test.
U
b
The value it should be less than.
string
message
The custom
message
to display instead of default.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldBeGreaterOrEqual
(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
T
a
The value to test.
U
b
The value it should be greater or equal than.
string
message
The custom
message
to display instead of default.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldBeLessOrEqual
(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
T
a
The value to test.
U
b
The value it should be less or equal than.
string
message
The custom
message
to display instead of default.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldThrow
(void delegate()cb
, stringfile
= __FILE__, size_tline
= __LINE__);Used for asserting that a delegate will throw an exception.
Parameters
void delegate()
cb
The delegate that is expected to throw the exception.
string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
shouldThrow
(stringmessage
, void delegate()cb
, stringfile
= __FILE__, size_tline
= __LINE__);Used for asserting that a delegate will throw an exception.
Parameters
void delegate()
cb
The delegate that is expected to throw the exception.
string
message
The
message
that is expected to be in the exception. Will not be tested, if it isnull
.string
file
The
file
name that the assert failed in. Should be left as default.size_t
line
The
file
line
that 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
void
describe
(stringdescribe_message
, ItFunc[]its
...);Used to
describe
the thing being tested. Contains many 'it' functions to test the thing.Parameters
string
describe_message
The thing that is being described.
ItFunc[]
its
All the 'it' functions that will test the thing.
Examples
describe("example_library#thing_to_test", it("Should NOT fail", delegate() { // test code here }) );
-
Declaration
void
describe
(stringdescribe_message
, BeforeFuncbefore
, ItFunc[]its
...);Used to
describe
the thing being tested. Contains many 'it' functions to test the thing. Also takes a function to runbefore
each test.Parameters
string
describe_message
The thing that is being described.
BeforeFunc
before
The function that will run
before
each 'it' function. If thebefore
function fails, the 'it' function will not be run.ItFunc[]
its
All 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
void
describe
(stringdescribe_message
, AfterFuncafter
, ItFunc[]its
...);Used to
describe
the thing being tested. Contains many 'it' functions to test the thing. Also takes a function to runafter
each test.Parameters
string
describe_message
The thing that is being described.
AfterFunc
after
The function that will run
after
each 'it' function. Will alwasy run, even if the 'before' or 'it' function failed.ItFunc[]
its
All 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
void
describe
(stringdescribe_message
, BeforeFuncbefore
, AfterFuncafter
, ItFunc[]its
...);Used to
describe
the thing being tested. Contains many 'it' functions to test the thing. Also takes a function to runbefore
, and a function to runafter
each test.Parameters
string
describe_message
The thing that is being described.
BeforeFunc
before
The function that will run
before
each 'it' function. If thebefore
function fails, the 'it' function will not be run.AfterFunc
after
The function that will run
after
each 'it' function. Will alwasy run, even if the 'before
' or 'it' function failed.ItFunc[]
its
All 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
ItFunc
it
(stringmessage
, void delegate()func
, stringfile
= __FILE__, size_tline
= __LINE__);The
message
should describe what the test should do.Parameters
string
message
The
message
to print when the test fails.void delegate()
func
The delegate to call when running the test.
string
file
The
file
name that the 'it
' is located in. Should be left as default.size_t
line
The
file
line
that 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
BeforeFunc
before
(void delegate()func
, stringfile
= __FILE__, size_tline
= __LINE__);The function to call
before
each 'it' function.Parameters
void delegate()
func
The function to call
before
running each test.string
file
The
file
name that the 'before
' is located in. Should be left as default.size_t
line
The
file
line
that 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
AfterFunc
after
(void delegate()func
, stringfile
= __FILE__, size_tline
= __LINE__);The function to call
after
each 'it' function.Parameters
void delegate()
func
The function to call
after
running each test.string
file
The
file
name that the 'after
' is located in. Should be left as default.size_t
line
The
file
line
that 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() { // }) );