Learn more about how DevOps teams must adopt a more agile development process, working in parallel instead of waiting on other teams to finish their components or for resources to become available, brought to you in partnership with CA Technologies.
In "Unit Test Case, Subject Matter Experts and Requirements
I suggested that it's often pretty easy to get a spreadsheet of
full-worked out examples from subject-matter experts. Indeed, if your
following TDD, that spreadsheet of examples is solid gold.
consider something relatively simple. Let's say we're working on some
fancy calculations. Our users explain until they're blue in the face.
We take careful notes. We think we understand. To confirm, we ask for a simple spreadsheet with inputs and outputs.
|Latitude 1||Longitude 1||Latitude 2||Longitude 2||range||bearing|
|50 21 50N||004 09 25W||42 21 04N||071 02 27W||2805 nm||260 07 38|
Only it has a a few more rows with different examples. Equator Crossing. Prime Meridian Crossing. All the usual suspects.
TDD Means Making Test Cases
one, then, is to parse the spreadsheet full of examples and create some
domain-specific examples. Since it's far, far easier to work with .CSV
files, we'll presume that we can save the carefully-crafted spreadsheet
as a simple .CSV with the columns shown above.
Step two will be to create working Python code from the domain-specific examples.
creation of test cases is a matter of building some intermediate
representation out of the spreadsheet. This is where plenty of parsing
and obscure special-case data handling may be necessary.
from __future__ import division
from collections import namedtuple
def latlon( txt ):
match= latlon_pat.match( txt )
d, m, s, h = match.groups()
return float(d)+float(m)/60+float(s)/3600, h
def angle( txt ):
match= angle_pat.match( txt )
d, m, s = match.groups()
def range( txt ):
match= range_pat.match( txt )
d, units = match.groups()
return float(d), units
def test_iter( filename="sample_data.csv" ):
with open(filename,"r") as source:
rdr= csv.DictReader( source )
for row in rdr:
latlon(row['Latitude 1']), latlon(row['Longitude 1']),
latlon(row['Latitude 2']), latlon(row['Longitude 2']),
for tc in test_iter():
This shows a simple template with values filled in. Often, we have to
generate a hair more than this. A few imports, a "unittest.main()" is
usually sufficient to transform a spreadsheet into unit tests that we
can confidently use for test-driven development.
Discover the warning signs of DevOps Dysfunction and learn how to get back on the right track, brought to you in partnership with CA Technologies.