Automated testing
Aistė Stikliūtė @ Vilnius Girls Code 2015-06-17
Me
● Career in software testing
● Testing classes
● Me in the community
Today - Test automation
● Why
● What
● How (high level + examples)
○ UI (Selenium)
○ API (SpecFlow + RestSharp)
● TDD / BDD
Why automate testing?
Can testing be automated?
James Bach:
there’s no automated testing, there’s automated checking!
Does it really pay off?
● New / legacy system?
● Waterfall / Agile?
● How difficult to automate?
● Team’s discipline?
● Personal motivation?
● Continuous delivery?
Continuous delivery
software engineering approach -
keep producing valuable software
that can be
reliably released anytime
Continuous D. benefits
● Accelerated Time to Market
● Building the Right Product
● Improved Productivity and Efficiency
● Reliable Releases
● Improved Product Quality
● Improved Customer Satisfaction
Personal motivation
In between testing and development...
Domain expert
Enjoys coding
Problem solverProblem finder
Usability expert
Has technical skillsHacker
Automated test types
● Functional tests:
○ Unit tests
○ Integration tests
○ End-to-end tests
● Performance tests
● Security tests
● Usability
What tests can be automated?
* to certain extent!
What cannot / should not?
● The “first look”
● Functional suitability
● Some security tests
● Some operations tests
● Real user experience tests
● Very alternative scenarios (?)
Which are most important?
The ones you will use!
● My bet: some of the functional tests
● Unit tests - fastest, find fewest bugs
● End-to-end - slowest, find bugs
● Integration - in the middle
How to ....
automated tests?
Rule #1 - make them visible
● Dashboards
● Notifications
● Attract attention:
○ QAs
○ Developers
○ Management
● Each commit?
● Nightly?
● After deployment to different environment?
○ Even PROD (special suite)?
Rule #2 - run tests often
Look ASAP: are they green?
Rule #3 - keep them green
● Fix system / tests immediately
○ Unstable tests - (almost) worthless
■ Change / refactor tests
■ Maybe change the system?
■ If nothing else works - automate retrying
○ 1 test keeps failing - test suite (almost) worthless
■ Tmp commenting / ignoring may be OK
Rule #4 - include tests in DoD
● Feature not finished
until it has automated tests
● Automated tests - team’s responsibility
* DoD - Definition of Done
Rule #5 - automate bugfix tests
I’m baaack! :)
Coverage… ?
* Rodin's The Thinker
GUI / end-to-end tests with Selenium
Selenium
IDE vs. WebDriver
Script ←→ Browser ←→ Click, type, drag&drop, etc.
GUI / end-to-end ?
Selenium WebDriver
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
query.Submit();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.
FromSeconds(10));
wait.Until( (d) => { return d.Title.ToLower().StartsWith
("cheese"); });
driver.Quit();
Page Object pattern
public class LoginPage {
public HomePage loginAs(String username, String password) {
// ... clever magic happens here
}
public LoginPage loginAsExpectingError(String username,
String password) {
// ... failed login here
}
public String getErrorMessage() {
// So we can verify that the correct error is shown
}
}
API tests with SpecFlow & RestSharp
What is REST API and why test it?
● Web architectural style with a set of constraints
● Web service APIs that adhere to the constraints - RESTful
Rest API: typically used HTTP methods
Resource GET POST PUT DELETE
Collection URI, such as
http://api.example.
com/books/
List
collection
members
Create
new entry
in the
collection
Replace the
entire
collection
Delete the
entire
collection
Element URI, such as
http://api.example.
com/books/book17
Retrieve
the member
of the
collection
Not
generally
used
Replace the
member of the
collection
Delete the
member of the
collection.
SpecFlow. Gherkin language
GIVEN book with ISBN “1-84356-028-3” is in the system
AND it’s available quantity is 9
WHEN I add a book with ISBN “1-84356-028-3”
THEN the book is successfully added to the list
AND available qty. for book with ISBN “1-84356-028-3” is 10
SpecFlow: scenario implementation
SpecFlow: running tests
Test / Business Driven Development
Test-first automation approach
TDD:
● Developer writes tests, then writes code until tests pass
BDD:
● PO / QA / team write tests
● Developer implements tests
● Developer writes code until tests pass
That’s it!
For starters :)

Automated testing

  • 1.
    Automated testing Aistė Stikliūtė@ Vilnius Girls Code 2015-06-17
  • 2.
    Me ● Career insoftware testing ● Testing classes ● Me in the community
  • 3.
    Today - Testautomation ● Why ● What ● How (high level + examples) ○ UI (Selenium) ○ API (SpecFlow + RestSharp) ● TDD / BDD
  • 4.
  • 5.
    Can testing beautomated? James Bach: there’s no automated testing, there’s automated checking!
  • 6.
    Does it reallypay off? ● New / legacy system? ● Waterfall / Agile? ● How difficult to automate? ● Team’s discipline? ● Personal motivation? ● Continuous delivery?
  • 7.
    Continuous delivery software engineeringapproach - keep producing valuable software that can be reliably released anytime
  • 8.
    Continuous D. benefits ●Accelerated Time to Market ● Building the Right Product ● Improved Productivity and Efficiency ● Reliable Releases ● Improved Product Quality ● Improved Customer Satisfaction
  • 9.
    Personal motivation In betweentesting and development... Domain expert Enjoys coding Problem solverProblem finder Usability expert Has technical skillsHacker
  • 10.
  • 11.
    ● Functional tests: ○Unit tests ○ Integration tests ○ End-to-end tests ● Performance tests ● Security tests ● Usability What tests can be automated? * to certain extent!
  • 12.
    What cannot /should not? ● The “first look” ● Functional suitability ● Some security tests ● Some operations tests ● Real user experience tests ● Very alternative scenarios (?)
  • 13.
    Which are mostimportant? The ones you will use! ● My bet: some of the functional tests ● Unit tests - fastest, find fewest bugs ● End-to-end - slowest, find bugs ● Integration - in the middle
  • 14.
  • 15.
    Rule #1 -make them visible ● Dashboards ● Notifications ● Attract attention: ○ QAs ○ Developers ○ Management
  • 16.
    ● Each commit? ●Nightly? ● After deployment to different environment? ○ Even PROD (special suite)? Rule #2 - run tests often Look ASAP: are they green?
  • 17.
    Rule #3 -keep them green ● Fix system / tests immediately ○ Unstable tests - (almost) worthless ■ Change / refactor tests ■ Maybe change the system? ■ If nothing else works - automate retrying ○ 1 test keeps failing - test suite (almost) worthless ■ Tmp commenting / ignoring may be OK
  • 18.
    Rule #4 -include tests in DoD ● Feature not finished until it has automated tests ● Automated tests - team’s responsibility * DoD - Definition of Done
  • 19.
    Rule #5 -automate bugfix tests I’m baaack! :)
  • 20.
  • 21.
    GUI / end-to-endtests with Selenium
  • 22.
    Selenium IDE vs. WebDriver Script←→ Browser ←→ Click, type, drag&drop, etc. GUI / end-to-end ?
  • 23.
    Selenium WebDriver IWebDriver driver= new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.google.com/"); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("Cheese"); query.Submit(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan. FromSeconds(10)); wait.Until( (d) => { return d.Title.ToLower().StartsWith ("cheese"); }); driver.Quit();
  • 24.
    Page Object pattern publicclass LoginPage { public HomePage loginAs(String username, String password) { // ... clever magic happens here } public LoginPage loginAsExpectingError(String username, String password) { // ... failed login here } public String getErrorMessage() { // So we can verify that the correct error is shown } }
  • 25.
    API tests withSpecFlow & RestSharp
  • 26.
    What is RESTAPI and why test it? ● Web architectural style with a set of constraints ● Web service APIs that adhere to the constraints - RESTful
  • 27.
    Rest API: typicallyused HTTP methods Resource GET POST PUT DELETE Collection URI, such as http://api.example. com/books/ List collection members Create new entry in the collection Replace the entire collection Delete the entire collection Element URI, such as http://api.example. com/books/book17 Retrieve the member of the collection Not generally used Replace the member of the collection Delete the member of the collection.
  • 28.
    SpecFlow. Gherkin language GIVENbook with ISBN “1-84356-028-3” is in the system AND it’s available quantity is 9 WHEN I add a book with ISBN “1-84356-028-3” THEN the book is successfully added to the list AND available qty. for book with ISBN “1-84356-028-3” is 10
  • 29.
  • 30.
  • 31.
    Test / BusinessDriven Development
  • 32.
    Test-first automation approach TDD: ●Developer writes tests, then writes code until tests pass BDD: ● PO / QA / team write tests ● Developer implements tests ● Developer writes code until tests pass
  • 33.