What Jasmine thinks of a Given-When-Then syntax

May I introduce you to Jasmine!

Jasmine BDD is a test automation framework to test JavaScript code. It is designed for Behaviour Driven Development by using specifications to describe the aim of a test in plain English language.
Example of a Jasmine test:

it(“makes testing JavaScript awesome!”, function() {
// your test code
});

This specification will result in a readable test report like
“Test that it makes testing JavaScript awesome!”

Behaviour Driven Development with Jasmine

Behaviour-Driven-Development is a way of focusing on the behavioural aspects of software.
So let’s have a look on an example using BDD that is understandable for Developers, QAs as well as Product Owners and Business people.
GIVEN a customer previously bought a black sweater from me
AND I currently have 3 black sweaters left in stock
WHEN the customer returns the sweater for a refund
THEN I should have 4 black sweaters in stock
That’s pretty easy to understand, isn’t it?

Jasmine can understand and interpret Given-When-Then

To bring this description into a scripting language we modified the Jasmine framework to use a Given-When-Then notation within the executable test script.

it(“adds a sweater to the stock when returning it for refund”, function() {
given(“app.opened = true”);
and(“app.stockCount = 3”);
when(“app.returnForRefund => true”);
then(“app.stockCount = 4”);
});

To call specific methods on an object respectively to read the state of an object we provide Test Fixtures.  A Test Fixture is a kind of a proxy between the script executing the test and the application/component under test.

What are the benefits

In our case the benefits are readable, understandable as well as easy to write test scripts for both Developers and QAs. Test Fixtures are written by Developers and can be used by QAs to assemble the test scripts whether for a component in isolation or for a set of components according to the acceptance criteria of a story.
You might also like:
Jasmine
JsTestDriver
Behaviour Driven Development

2 thoughts on “What Jasmine thinks of a Given-When-Then syntax”

  1. Hi. As I understand it is your extension to jasmine. Is it published somewhere? I’m using jasmine for my tests and wish given-when-then functionality very much.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *