Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Rob Hasker. More notes on Cucumber  Can replace Given/When/Then by bullets Feature: Refund item Sales associates required by law to refund purchases.

Similar presentations


Presentation on theme: "Dr. Rob Hasker. More notes on Cucumber  Can replace Given/When/Then by bullets Feature: Refund item Sales associates required by law to refund purchases."— Presentation transcript:

1 Dr. Rob Hasker

2 More notes on Cucumber  Can replace Given/When/Then by bullets Feature: Refund item Sales associates required by law to refund purchases Scenario: Jeff returns a faulty microwave Given Jeff has bought a microwave for $100 And he has a receipt# don’t assume this is true! When he returns the microwave Then Jeff should be refunded $100

3 More notes on Cucumber  Can replace Given/When/Then by bullets Feature: Refund item Sales associates required by law to refund purchases Scenario: Jeff returns a faulty microwave Given Jeff has bought a microwave for $100 And he has a receipt# don’t assume this is true! When he returns the microwave Then Jeff should be refunded $100 Feature: Refund item Sales associates required by law to refund purchases Scenario: Jeff returns a faulty microwave * Jeff has bought a microwave for $100 * he has a receipt# don’t assume this is true! * he returns the microwave * Jeff should be refunded $100 So is this better?

4 More notes on Cucumber  Stateless scenario! Each scenario must make sense by self No dependencies between scenarios! ○ Eg: adding to account balance in one, using that balance in another Dependencies: frequent failures, difficult maintenance  Solution Before hooks can be set up to execute before scenarios Write a step definition for a common case: “customer has a bag of groceries” ○ Step definition: set up bag object w/ predefined contents

5 More notes on Cucumber  Frequent problem: names become stale (out- of-step with goals)  Best practice: name scenarios by Given, When clauses ○ These won’t change much! Don’t name them by the Then clause ○ Generally what changes when requirements change!

6 UI Testing in Java  Assumption: painful but readily available  Research: lots of vaporware, abandonware Many solutions for web, but not a lot for Java FrogLogic, RAutomation, MarathonTesting, UISpec4J, Mspec, abbot  Method that works: JavaWorld TestUtils; see also counter.zip JavaWorld TestUtilscounter.zip

7 UI Testing in Java  Each component: call.setName with unique string  Test code: TestUtils.getChildNamed(frame, name-of-child)  Use.doClick,.value(), etc. to exercise code  Robust Doesn’t depend on screen locations, specialized test frameworks But no auto-capture/replay

8 UI Testing in C++ w/ Cucumber Feature: Subtraction In order to avoid silly mistakes As a math-challenged person I want to be told the difference of two numbers Scenario Outline: Subtract two numbers Given I just turned on the calculator When I press And I press subtract And I press And I press calculate Then the display should show Examples: | button1 | button2 | result | | 2 | 3 | -1 | | 7 | 5 | 2 | | 9 | 1 | 8 | From https://github.com/cucumber/cucumber-cpp

9 UI Testing in C++ w/ Cucumber Feature: Subtraction In order to avoid silly mistakes As a math-challenged person I want to be told the difference of two numbers Scenario Outline: Subtract two numbers Given I just turned on the calculator When I press And I press subtract And I press And I press calculate Then the display should show Examples: | button1 | button2 | result | | 2 | 3 | -1 | | 7 | 5 | 2 | | 9 | 1 | 8 | GIVEN("^I just turned on the calculator$") { cucumber::ScenarioScope calculator; calculator->move(0, 0); calculator->show(); QTest::qWaitForWindowShown(calculator.get()); QTest::qWait(millisecondsToWait()); }

10 UI Testing in C++ w/ Cucumber Feature: Subtraction In order to avoid silly mistakes As a math-challenged person I want to be told the difference of two numbers Scenario Outline: Subtract two numbers Given I just turned on the calculator When I press And I press subtract And I press And I press calculate Then the display should show Examples: | button1 | button2 | result | | 2 | 3 | -1 | | 7 | 5 | 2 | | 9 | 1 | 8 | WHEN("^I press (\\d+)$") { REGEX_PARAM(unsigned int, n); cucumber::ScenarioScope calculator; QTest::keyClick(calculator.get(), Qt::Key_0 + n, Qt::NoModifier, millisecondsToWait()); } WHEN("^I press subtract") { cucumber::ScenarioScope calculator; QTest::keyClick(calculator.get(), Qt::Key_Minus, Qt::NoModifier, millisecondsToWait()); }

11 UI Testing in C++ w/ Cucumber Feature: Subtraction In order to avoid silly mistakes As a math idiot I want to be told the difference of two numbers Scenario Outline: Subtract two numbers Given I just turned on the calculator When I press And I press subtract And I press And I press calculate Then the display should show Examples: | button1 | button2 | result | | 2 | 3 | -1 | | 7 | 5 | 2 | | 9 | 1 | 8 | WHEN("^I press calculate") { cucumber::ScenarioScope calculator; QTest::keyClick(calculator.get(), Qt::Key_Return, Qt::NoModifier, millisecondsToWait()); } THEN("^the display should show (.*)$") { REGEX_PARAM(QString, expected); cucumber::ScenarioScope calculator; BOOST_CHECK_EQUAL(expected, calculator->display()); QTest::qWait(millisecondsToWait()); }

12 Acceptance Tests & APIs  How to write acceptance tests for an API? Our model: acceptance test = story/scenario Issue: an API is not a user!  Solution: Cohn: Writing User Stories for Back-end SystemsCohn: Writing User Stories for Back-end Systems Personify subsystems Epic: “As a bank, I want to receive a file showing all checks to be cleared so that I can debit and credit the right accounts.” “As a bank, I want to receive a 5300 file with correctly formatted single-line deposit entry records so that I can process them.” Write test to the resulting story.

13 Review  UI Testing with Java: TestUtils  UI Testing in C++ w/ Qt: cucumber-cpp  Acceptance testing for APIs


Download ppt "Dr. Rob Hasker. More notes on Cucumber  Can replace Given/When/Then by bullets Feature: Refund item Sales associates required by law to refund purchases."

Similar presentations


Ads by Google