Chapter 5. High Level Customer Scenarios with Acceptance Testing

In this chapter, we will cover:

  • Installing Pyccuracy
  • Testing the basics with Pyccuracy
  • Using Pyccuracy to verify web app security
  • Installing the Robot Framework
  • Creating a data-driven test suite with Robot
  • Writing a testable story using Robot
  • Tagging Robot tests and running a subset
  • Testing web basics with Robot
  • Using Robot to verify web app security
  • Creating a project-level script to run this chapter's acceptance tests

Introduction

Acceptance testing involves writing tests to prove our code is, well, acceptable! But what does this mean? The context implies acceptable from a customer's perspective. Customers are usually more interested in what the software does, not how it does it. This means that tests are aimed at inputs and outputs and tend to be at a higher level than unit testing. This has sometimes been called black box testing, and is usually more system oriented. At the end of the day, it is often associated with testing that asserts whether or not the customer will accept the software.

There is an assumption amongst some developers that acceptance testing involves verifying the front end of web applications. In fact, several testing tools, including Pyccuracy, are built on the sole premise of testing web applications. When viewed from the perspective of whether or not a customer will accept the software, this would quite literally fit into acceptable from a customer's perspective.

But web testing isn't the only form of acceptance testing. Not all systems are web-based. If a subsystem is to be built by one team, and handed off to another team that plans to build another layer on top of it, an acceptance test may be required before the second team will accept it.

In this chapter, we will dig into some recipes that involve both web and non-web application acceptance testing.

To create an e-store web application for testing, follow these steps.

  1. Make sure you have mercurial installed on your system.
    • For Mac, use either mac ports or home brew.
    • For Ubuntu/Debian, use sudo apt-get install mercurial
    • For other systems, you will need to do extra research in installing mercurial.
  2. This also requires having compilable tools installed, like gcc.
    • For Ubuntu, use sudo apt-get install build-essential
    • For other systems, you will need to do extra research in installing gcc.
  3. Install satchmo, an e-commerce website builder, by typing the following commands:
    pip install -r http://bitbucket.org/gturnquist/satchmo/raw/tip/scripts/requirements.txt
    pip install -e hg+http://bitbucket.org/gturnquist/satchmo/#egg=satchmo
  4. Install Python's PIL library for image processing: pip install PIL.
  5. Edit <virtualenv root>/lib/python2.6/site-packages/django/contrib/admin/templates/admin/login.html to add id="login" to the Log in <input> tag. This allows Pyccuracy to grab the Log in button and 'click' it.
  6. Run the satchmo script to create a store application: clonesatchmo.py.
  7. When prompted about creating a super-user, say yes.
  8. When prompted, enter a username.
  9. When prompted, enter an e-mail address.
  10. When prompted, enter a password.
  11. Go into the store directory: cd store.
  12. Startup store app: python manage.py runserver.

Tip

If you have issues installing satchmo with these steps, visit the project site at http://www.satchmoproject.com and possibly their support group at http://groups.google.com/group/satchmo-users.

To create a non-web shopping cart application for testing, create cart.py with the following code:

class ShoppingCart(object):
    def __init__(self):
        self.items = []

    def add(self, item, price):
        for cart_item in self.items:
            # Since we found the item, we increment
            # instead of append
            if cart_item.item == item:
                cart_item.q += 1
                return self

        # If we didn't find, then we append
        self.items.append(Item(item, price))
        return self

    def item(self, index):
        return self.items[index-1].item

    def price(self, index):
        return self.items[index-1].price * self.items[index-1].q
    def total(self, sales_tax):
        sum_price = sum([item.price*item.q for item in self.items])
        return sum_price*(1.0 + sales_tax/100.0)

    def __len__(self):
        return sum([item.q for item in self.items])

class Item(object):
    def __init__(self, item, price, q=1):
        self.item = item
        self.price = price
        self.q = q

This shopping cart:

  • Is 1-based, meaning the first item and price are at [1] not [0]
  • Includes the ability to have multiples of the same item
  • Will calculate total price and then add taxes

This application isn't complex. Maybe it doesn't look exactly at a system level, but it does provide an easy application to write acceptance tests against.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.221.133