Glad you find this useful, and I find your feedback useful too because every thread like this one, helps me build up content for the automated testing best practices repository we’re building.
What I really want is that developers to truly know what they’re getting in to through a proper understanding of the problem, rather than someone just preaching to them what should and shouldn’t be done. So I hope the feedback below is good for you personally, and the next person that reads this thread.
To your point about:
I couldn’t agree more with good reuse, and here’s how I would do it with Gherkin. Consider this feature:
#Feature: Account holder same-bank money transfers
# As an Account Holder
# I want to transfer money from my bank account to other account holders in the same bank
# So that I can pay my dues
# @critical
# Scenario: Account has sufficient funds
# Given my bank account balance is $100
# And "James"'s bank account balance is $0
# When I transfer $20 to "James"'s bank account
Then my account balance should be $80
# And "James"'s account balance should be $20
Notice how “Then my account balance should be $80” contains a reference to the account domain model that contains the property balance with the value $80, where as a reusable “Then I should see $80
” does not contains any domain context.
Here’s how I would do code-reuse. The step definition for “Then my account balance should be $80
” looks like this:
this.Then(/^my account balance should be \$(\d+)$/, function (balance) {
var actualBalance = server.execute(function () {
return AccountHolders.findOne(Meteor.userId()).account.balance;
});
expect(actualBalance).toEqual(parseFloat(balance));
});
That’s purely testing the domain portion. We can also define a step for the UI testing portion:
this.Then(/^my account balance should be \$(\d+)$/, function (balance) {
var actualBalance = widgets.accountSummary.getBalance();
expect(actualBalance).toEqual(balance);
});
And now we have as much reuse as we like. Any time we need to test the account balance through the UI, we can use the accountSummary
widget, and any time we want to test the account balance through the domain, we use the domain directly.
For completeness, here’s the accountSummary
widget code:
function AccountSummaryWidget() {
var selectors = {
balance: '.account-summary__balance'
};
this.getBalance = function () {
return browser.getText(selectors.balance);
}
}
widgets.accountSummary = new AccountSummaryWidget();
As a side note, it’s really interesting how well the BEM syntax plays TDD’ing UI components. I was able to build out a React components from this test.