Python as a Testing Tool. Chris Withers



Similar documents
Python Testing with unittest, nose, pytest

Survey of Unit-Testing Frameworks. by John Szakmeister and Tim Woods

CIS 192: Lecture 13 Scientific Computing and Unit Testing

New Tools for Testing Web Applications with Python

Software Testing with Python

Advanced Topics: Biopython

Unit Testing webmethods Integrations using JUnit Practicing TDD for EAI projects

Test Driven Development in Python

Software Testing. Theory and Practicalities

Automated Testing with Python

Continuous Integration: Aspects in Automation and Configuration Management

Self-review 9.3 What is PyUnit? PyUnit is the unit testing framework that comes as standard issue with the Python system.

SpiraTest / SpiraTeam Automated Unit Testing Integration & User Guide Inflectra Corporation

Effective unit testing with JUnit

Unit testing with mock code EuroPython 2004 Stefan Schwarzer p.1/25

MarathonITE. GUI Testing for Java/Swing Applications

How To Test Your Code

Fail early, fail often, succeed sooner!

Python and Google App Engine

JDemo - Lightweight Exploratory Developer Testing

Open Source HTTP testing tool. Stefane Fermigier

The Process Guidelines should be used in conjunction with the standard OUM process guidelines when using Testing and Quality Management Tools.

Unit Testing with FlexUnit. by John Mason

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

Unit Testing with zunit

Rake Task Management Essentials

Computer Forensics for Business Leaders: Building Robust Policies and Processes Transcript

Peach Fuzzer Platform

Writing robust scientific code with testing (and Python) Pietro Berkes, Enthought UK

Implementing Continuous Integration Testing Prepared by:

Test case design techniques I: Whitebox testing CISS

RUP. Development Process. Iterative Process (spiral) Waterfall Development Process. Agile Development Process. Well-known development processes

IERG 4080 Building Scalable Internet-based Services

Getting Started With Automated Testing. Michael Kelly

Market Challenges Business Drivers

How To Develop Software

Software Configuration Management Best Practices for Continuous Integration

Levels of Software Testing. Functional Testing

Jazz Source Control Best Practices

Introduction to C Unit Testing (CUnit) Brian Nielsen Arne Skou

Effective feedback from quality tools during development

Higher Focus on Quality. Pressure on Testing Budgets. ? Short Release Cycles. Your key to Effortless Automation. OpKey TM

Part II. Managing Issues

An Introduction to text-based test automation and the TextTest tool

Techniques and Tools for Rich Internet Applications Testing

Table of Contents. LESSON: The JUnit Test Tool...1. Subjects...2. Testing What JUnit Provides...4. JUnit Concepts...5

Outline. 1 Denitions. 2 Principles. 4 Implementation and Evaluation. 5 Debugging. 6 References

Code Qualities and Coding Practices

A Pythonic Approach to Continuous Delivery

Software Construction

Quality Cruising. Making Java Work for Erlang. Erik (Happi) Stenman

Chapter 8 Software Testing

Approach of Unit testing with the help of JUnit

Testing. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies. CHAPTER AUTHORS Michael Atmadja Zhang Shuai Richard

SOFTWARE TESTING TRAINING COURSES CONTENTS

Mobile Application Languages XML, Java, J2ME and JavaCard Lesson 04 Java

MarkLogic Server. Reference Application Architecture Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

Executive Summary On IronWASP

4. Test Design Techniques

Microsoft Windows PowerShell v2 For Administrators

Automated Integration Testing & Continuous Integration for webmethods

Effective Team Development Using Microsoft Visual Studio Team System

Getting Things Done: Practical Web/e-Commerce Application Stress Testing

What is new in Switch 12

Wrestling with Python Unit testing. Warren Viant

Course 10777A: Implementing a Data Warehouse with Microsoft SQL Server 2012

Software Manual LSeries Manager V1.2 Software Manual June 18, LSeries Manager 1.2. Software Manual

SOFTWARE DEVELOPMENT BASICS SED

Building, testing and deploying mobile apps with Jenkins & friends

Implementing a Data Warehouse with Microsoft SQL Server 2012

Profiling, debugging and testing with Python. Jonathan Bollback, Georg Rieckh and Jose Guzman

Development Lifecycle Guide

SMock A Test Platform for the Evaluation of Monitoring Tools

The Customer. Manual and Automation Testing for a leading Enterprise Information Management (EIM) Solution provider. Business Challenges

Continuous integration End of the big bang integration era

Automatic promotion and versioning with Oracle Data Integrator 12c

SoMA. Automated testing system of camera algorithms. Sofica Ltd

Kaseya 2. User Guide. Version 1.1

Ubuntu Linux Reza Ghaffaripour May 2008

Introduction to Software Testing Chapter 8.1 Building Testing Tools Instrumentation. Chapter 8 Outline

Testing Automation for Distributed Applications By Isabel Drost-Fromm, Software Engineer, Elastic

here: styleguide.googlecode.com/svn/trunk/javascriptguide.xml.

Subversion Integration for Visual Studio

Dry Dock Documentation

IR180 May Gaming machine duty. A guide for organisations that operate gaming machines. Classified Inland Revenue - Public

Unit Testing & JUnit

Implementing a Data Warehouse with Microsoft SQL Server 2012

Kafka & Redis for Big Data Solutions

The Agile Movement An introduction to agile software development

Transcription:

Python as a Testing Tool Chris Withers

Who am I? Chris Withers Independent Zope and Python Consultant Using Python since 1999 Fan of XP What do I use Python for? Content Management Systems Integration XML manipulation

The Plan Introduction to Testing Python's Unit Testing Framework Documentation Testing

Pre-requisites Knowledge of Python

Why Write Tests? Help define the problem you're solving Find unexpected breakage Automate a repetitive task Help with branching and merging

When to Test? Before any code is written ideally... When you find a bug Make sure your test fails before it passes!

Types of Testing Functional testing replay scenarios good for customer acceptance Unit testing each tests one behaviour of one function or method Documentation testing makes sure your examples work python specific

What to Unit Test? Smallest unit of functionality possible Why? better chance you're testing what you think you're testing less chance of two wrongs making a right Each type of behaviour make sure edge cases are covered

The unittest module Python's unit testing framework Added in Python 2.1 Based on PyUnit which was based on JUnit

How to Write a Test The code we want to test def reverse(alist): alist.reverse() return alist example1.py The test import unittest class ReverseTests(unittest.TestCase): example1t.py def test_normal(self): # do import here, makes test independent from example1 import reverse # can use python's normal asserts assert reverse([1,2,3])==[3,2,1] # or more robust and informative unittest options self.assertequal(reverse([1,2,3]),[3,2,1])

How to Run a Test unittest provides several ways here's one... import unittest class ReverseTests(unittest.TestCase): def test_normal(self): # do import here, makes test independent from example1 import reverse # can use python's normal asserts assert reverse([1,2,3])==[3,2,1] # or more robust and informative unittest options self.assertequal(reverse([1,2,3]),[3,2,1]) if name ==" main ": unittest.main()

Helpful Methods fail(message) assertequals(x,y) failunless(expression) failifexpression assertraises(exception,callable,arg1,arg2,...) Make sure it's clear why you've written the testing code that's there!

setup and teardown Unit Tests should be... Atomic Independent Discrete Concurrent well maybe not... How do we do this? start from fresh for each script write tests carefully

setup and teardown Called for each test in a suite Should NOT fail or consume resource if they do class ReverseTests(unittest.TestCase): def setup(self): from example2 import reverse self.reverse = reverse self.alist = [1,2,3] def teardown(self): del self.alist example2t.py def test_normal(self): self.assertequal(self.reverse([1,2,3]),[3,2,1]) def test_doesntmutate(self): self.assertequal(self.reverse(self.alist),[3,2,1]) self.assertequal(self.alist,[1,2,3])

Good Testing Practice Watch your imports They can fail! Use factory methods class MyTests(unittest.TestCase): def _creatething(self,name): from thing import Thing return Thing(name) def test_thing_name(self): self.assertequal(self._creatething('test').name,'test')

Good Testing Practice Create base test classes Create re-usable test suites can be used on multiple implementations class basetest(unittest.testcase): klass = NotImplemented def _create(self.name): return self.klass(name) def test1(self): o = self._create('test') self.assertequal( o.getname(), 'test' ) from imps import Imp1, Imp2 from base import basetest class Imp1Test(baseTest): pass class Imp2Test(baseTest): def testextra(self): o = self._create('test') self.assertequal( o.getextra(), 'TEST' ) def test1(self): pass

Good Testing Practice Destroy all fixtures Reset environment after each test class TestDB(unittest.TestCase): def setup(self): self._db = OpenDB() self._db.begintransaction() self._db.clearalltables() # known start state def teardown(self): self._db.aborttransaction() del self._db def test_one(self): # interesting discussion, what does this test: self._db.insert('fish') self.assertequal( self._db.select('animals from table'), ['fish'] )

Limitations Test discovery large multi-package applications lots of tests python's package infrastructure doesn't help! Hand-maintained script test can get forgotten Heuristic discovery can find things that aren't tests

Limitations Testing other languages can't test for language specific problems memory leakage pointers out don't get good feedback... Testing other frameworks GUI's, etc Should be handled by Functional Tests

DocTest Been around for a while Finally getting exposure Lets have a look at example3.py

The End Any questions?

Thankyou! Chris Withers Do people want these slides to be available?