In this chapter, we will cover:
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.
mercurial
installed on your system.mac
ports
or home
brew
.sudo
apt-get
install
mercurial
mercurial
.gcc
.sudo
apt-get
install
build-essential
gcc
.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
PIL
library for image processing: pip install PIL
.<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.satchmo
script to create a store application: clonesatchmo.py
.yes
.username
.e-mail
address
.password
.cd store
.python manage.py runserver
.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:
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.
3.15.221.133