1 / 13

SE 3800 Note 6 UI Testing

Dr. Rob Hasker. SE 3800 Note 6 UI Testing. 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

matthews
Télécharger la présentation

SE 3800 Note 6 UI Testing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dr. Rob Hasker SE 3800Note 6UI Testing

  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: • JavaWorldTestUtils; see also counter.zip

  7. UI Testing in Java • Each component: call .setNamewith 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 <button1> And I press subtract And I press <button2> And I press calculate Then the display should show <result> 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 <button1> And I press subtract And I press <button2> And I press calculate Then the display should show <result> Examples: | button1 | button2 | result | | 2 | 3 | -1 | | 7 | 5 | 2 | | 9 | 1 | 8 | GIVEN("^I just turned on the calculator$") { cucumber::ScenarioScope<CalculatorWidget> calculator; calculator->move(0, 0); calculator->show(); QTest::qWaitForWindowShown(calculator.get()); QTest::qWait(millisecondsToWait()); }

  10. UI Testing in C++ w/ Cucumber WHEN("^I press (\\d+)$") { REGEX_PARAM(unsigned int, n); cucumber::ScenarioScope<CalculatorWidget> calculator; QTest::keyClick(calculator.get(), Qt::Key_0 + n, Qt::NoModifier, millisecondsToWait()); } 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 <button1> And I press subtract And I press <button2> And I press calculate Then the display should show <result> Examples: | button1 | button2 | result | | 2 | 3 | -1 | | 7 | 5 | 2 | | 9 | 1 | 8 | WHEN("^I press subtract") { cucumber::ScenarioScope<CalculatorWidget> calculator; QTest::keyClick(calculator.get(), Qt::Key_Minus, Qt::NoModifier, millisecondsToWait()); }

  11. UI Testing in C++ w/ Cucumber WHEN("^I press calculate") { cucumber::ScenarioScope<CalculatorWidget> calculator; QTest::keyClick(calculator.get(), Qt::Key_Return, Qt::NoModifier, millisecondsToWait()); } THEN("^the display should show (.*)$") { REGEX_PARAM(QString, expected); cucumber::ScenarioScope<CalculatorWidget> calculator; BOOST_CHECK_EQUAL(expected, calculator->display()); QTest::qWait(millisecondsToWait()); } 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 <button1> And I press subtract And I press <button2> And I press calculate Then the display should show <result> Examples: | button1 | button2 | result | | 2 | 3 | -1 | | 7 | 5 | 2 | | 9 | 1 | 8 |

  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 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

More Related