A U T O M AT E D T E S T I N G O F W E B A P P S +Jonatan Kronqvist @zch
}>
A G E N D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
A G E N D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
Unit Testing
Integration Testing
System Testing
Regression Testing
End-to-End Testing
Acceptance Testing
Load Testing
Create VALUE for Your Customers
– J O H N D O E V E L O P E R “Unit testing is a waste of time, because the tests don't prove that things work correctly”
Red Green Refactor
1. You will ALWAYS have code that worked a minute ago 2. You will have more and more automatic tests that can be run all the time 3. You will have usage examples for all of your code and API 4. All your code will be testable by default
Best ROI: • integration • regression • system
Most unit tests could be replaced by assertions
Focus on continuous integration and system testing
B E H AV I O R D R I V E N D E V E L O P M E N T
Scenario 1: Account has sufficient funds Given the account balance is $100 And the card is valid And the machine contains enough money When the Account Holder requests $20 Then the ATM should dispense $20 And the account balance should be $80 And the card should be returned
1. Easy to define end-to-end behavior to be tested 2. Business value easily translates to this format 3. You're probably already defining user stories
A G E N D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
• Cross browser differences • Logic that depends on the DOM • Asynchronous execution • Possibly slow execution
M V P Presenter Model (State) View Rendering logic Event handling logic
Avoid new – Dependency Injection
A G E N D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
Unit Testing?
Integration Testing?
System Testing?
End-to-end Testing?
Web automation
BDD framework + Selenium or Vaadin TestBench
Narrative:
 As a user
 I want to perform calculations
 So that I can easily get the results without calculating in my head
 
 Scenario: Calculate 1+2
 Given I have the calculator open
 When I push 1+2
 Then the result should be 3.0
public class CalculatorSteps extends TestBenchTestCase {
 
 private WebDriver driver;
 private CalculatorPageObject calculator;
 
 @BeforeScenario
 public void setUpWebDriver() {
 driver = TestBench.createDriver(new FirefoxDriver());
 calculator = PageFactory.initElements(driver, CalculatorPageObject.class);
 } @AfterScenario
 public void tearDownWebDriver() {
 driver.quit();
 }
@Given("I have the calculator open")
 public void theCalculatorIsOpen() {
 calculator.open();
 }
 
 @When("I push $buttons")
 public void enter(String buttons) {
 calculator.enter(buttons);
 }
 
 @Then("the result should be $result")
 public void assertResult(String result) {
 assertEquals(result, calculator.getResult());
 }
 }
public class SimpleCalculation extends JUnitStory {
 @Override
 public Configuration configuration() {
 return new MostUsefulConfiguration()
 .useStoryLoader(new LoadFromClasspath(this.getClass()))
 .useStoryReporterBuilder(new StoryReporterBuilder() .withDefaultFormats() .withFormats(Format.CONSOLE, Format.TXT));
 }
 
 @Override
 public InjectableStepsFactory stepsFactory() {
 return new InstanceStepsFactory(configuration(), new CalculatorSteps());
 }
 }
}> >2500 tests <15 minutes each commit
Load Testing
A G E N D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
WHAT SHOULD I DO?
Architect for testability and flexibility
Focus on Integration, End-to-end and System Tests
Try TDD, but don't sweat it
Use BDD
Don't forget to load test!
ENSURE VALUE IS CREATED FOR YOUR CUSTOMERS
Q & A Please rate the presentation at gwtcreate.com/agenda
I M A G E S U S E D • https://flic.kr/p/671Z4A • https://flic.kr/p/bsozXc • https://flic.kr/p/hRfBC • https://flic.kr/p/nQ7ac5 • https://flic.kr/p/8sf5Xt • https://flic.kr/p/4LH5Eo • https://flic.kr/p/7Lx9Kk • https://flic.kr/p/nAi4GZ • https://flic.kr/p/eguHX8 • https://flic.kr/p/4fmu9E • https://flic.kr/p/dtSHid • https://flic.kr/p/bwpVQ7 • https://flic.kr/p/fGyo6Q

Automated Testing of Web Applications

  • 1.
    A U TO M AT E D T E S T I N G O F W E B A P P S +Jonatan Kronqvist @zch
  • 4.
  • 6.
    A G EN D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
  • 7.
    A G EN D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
    Create VALUE forYour Customers
  • 17.
    – J OH N D O E V E L O P E R “Unit testing is a waste of time, because the tests don't prove that things work correctly”
  • 19.
  • 20.
    1. You willALWAYS have code that worked a minute ago 2. You will have more and more automatic tests that can be run all the time 3. You will have usage examples for all of your code and API 4. All your code will be testable by default
  • 21.
    Best ROI: • integration •regression • system
  • 22.
    Most unit testscould be replaced by assertions
  • 23.
    Focus on continuousintegration and system testing
  • 24.
    B E HAV I O R D R I V E N D E V E L O P M E N T
  • 25.
    Scenario 1: Accounthas sufficient funds Given the account balance is $100 And the card is valid And the machine contains enough money When the Account Holder requests $20 Then the ATM should dispense $20 And the account balance should be $80 And the card should be returned
  • 26.
    1. Easy todefine end-to-end behavior to be tested 2. Business value easily translates to this format 3. You're probably already defining user stories
  • 27.
    A G EN D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
  • 29.
    • Cross browserdifferences • Logic that depends on the DOM • Asynchronous execution • Possibly slow execution
  • 30.
  • 31.
    Avoid new –Dependency Injection
  • 32.
    A G EN D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
    BDD framework +Selenium or Vaadin TestBench
  • 41.
    Narrative:
 As a user
 Iwant to perform calculations
 So that I can easily get the results without calculating in my head
 
 Scenario: Calculate 1+2
 Given I have the calculator open
 When I push 1+2
 Then the result should be 3.0
  • 42.
    public class CalculatorStepsextends TestBenchTestCase {
 
 private WebDriver driver;
 private CalculatorPageObject calculator;
 
 @BeforeScenario
 public void setUpWebDriver() {
 driver = TestBench.createDriver(new FirefoxDriver());
 calculator = PageFactory.initElements(driver, CalculatorPageObject.class);
 } @AfterScenario
 public void tearDownWebDriver() {
 driver.quit();
 }
  • 43.
    @Given("I have thecalculator open")
 public void theCalculatorIsOpen() {
 calculator.open();
 }
 
 @When("I push $buttons")
 public void enter(String buttons) {
 calculator.enter(buttons);
 }
 
 @Then("the result should be $result")
 public void assertResult(String result) {
 assertEquals(result, calculator.getResult());
 }
 }
  • 44.
    public class SimpleCalculationextends JUnitStory {
 @Override
 public Configuration configuration() {
 return new MostUsefulConfiguration()
 .useStoryLoader(new LoadFromClasspath(this.getClass()))
 .useStoryReporterBuilder(new StoryReporterBuilder() .withDefaultFormats() .withFormats(Format.CONSOLE, Format.TXT));
 }
 
 @Override
 public InjectableStepsFactory stepsFactory() {
 return new InstanceStepsFactory(configuration(), new CalculatorSteps());
 }
 }
  • 46.
  • 47.
  • 48.
    A G EN D A • Software testing in general • Architecting for testability • Testing web UIs • What should I do?
  • 49.
  • 50.
  • 51.
    Focus on Integration,End-to-end and System Tests
  • 52.
    Try TDD, butdon't sweat it
  • 53.
  • 54.
    Don't forget toload test!
  • 55.
    ENSURE VALUE ISCREATED FOR YOUR CUSTOMERS
  • 56.
    Q & A Pleaserate the presentation at gwtcreate.com/agenda
  • 57.
    I M AG E S U S E D • https://flic.kr/p/671Z4A • https://flic.kr/p/bsozXc • https://flic.kr/p/hRfBC • https://flic.kr/p/nQ7ac5 • https://flic.kr/p/8sf5Xt • https://flic.kr/p/4LH5Eo • https://flic.kr/p/7Lx9Kk • https://flic.kr/p/nAi4GZ • https://flic.kr/p/eguHX8 • https://flic.kr/p/4fmu9E • https://flic.kr/p/dtSHid • https://flic.kr/p/bwpVQ7 • https://flic.kr/p/fGyo6Q