Automated Testing with Python



Similar documents
Software Testing. Theory and Practicalities

Python as a Testing Tool. Chris Withers

Software Testing with Python

Python Testing with unittest, nose, pytest

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

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

CIS 192: Lecture 13 Scientific Computing and Unit Testing

Continuous Integration

Apache JMeter HTTP(S) Test Script Recorder

Automating Testing and Configuration Data Migration in OTM/GTM Projects using Open Source Tools By Rakesh Raveendran Oracle Consulting

Scalable Web Programming. CS193S - Jan Jannink - 1/12/10

Interlink Networks Secure.XS and Cisco Wireless Deployment Guide

Automating with IBM SPSS

Environment Modeling for Automated Testing of Cloud Applications

How To Test Your Code

Unit and Functional Testing for the ios Platform. Christopher M. Judd

So in order to grab all the visitors requests we add to our workbench a non-test-element of the proxy type.

Outline. 1. A bit about Bing 2. Velocity What does it mean? 4. Modern Engineering Principles 5. The inner and outer loop 6. Performance gating

Test Driven Development in Python

Web Applications Testing

Unit testing with JUnit and CPPUnit. Krzysztof Pietroszek

Publish Acrolinx Terminology Changes via RSS

Jenkins User Conference Herzelia, July #jenkinsconf. Testing a Large Support Matrix Using Jenkins. Amir Kibbar HP

Automate Your BI Administration to Save Millions with Command Manager and System Manager

TEST PLAN Issue Date: <dd/mm/yyyy> Revision Date: <dd/mm/yyyy>

APP INVENTOR. Test Review

Introduction to Functional Verification. Niels Burkhardt

Grandstream Networks, Inc. UCM6510 Basic Configuration Guide

Tutorial: Load Testing with CLIF

Advanced Software Testing

Virtual desktops made easy

INCREASE YOUR WEBMETHODS ROI WITH AUTOMATED TESTING. Copyright 2015 CloudGen, LLC

Python Loops and String Manipulation

SECTION 2 PROGRAMMING & DEVELOPMENT

VIP Help Desk Web Application User Guide Version 3.0

Tizen Compliance Test (TCT) Hojun Jaygarl (Samsung Electronics), Cathy Shen (Intel)

Business Process Testing Accelerator for PeopleSoft Applications

Automated Performance Testing of Desktop Applications

Open Source HTTP testing tool. Stefane Fermigier

Dealing with Device Fragmentation in Mobile Games Testing. Ru Cindrea - Altom Consulting

Grandstream Networks, Inc.

JMeter Testing. Identify Preformance acceptance criteria: Identfy throughput,response time and resource utilization goals and constraints.

Modern CI/CD and Asset Serving

Software Automated Testing

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

2X ApplicationServer & LoadBalancer Manual

Latest Research and Development on Software Testing Techniques and Tools

Levels of Software Testing. Functional Testing

It s Not Called Continuous Integration for Nothing!

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

Session 190 PD, Model Risk Management and Controls Moderator: Chad R. Runchey, FSA, MAAA

Application Modelling

Effective unit testing with JUnit

New Tools for Testing Web Applications with Python

DiskPulse DISK CHANGE MONITOR

MySQL Installer Guide

DRUPAL CONTINUOUS INTEGRATION. Part I - Introduction

A Comprehensive Approach to Master Data Management Testing

DEPLOYING EMC DOCUMENTUM BUSINESS ACTIVITY MONITOR SERVER ON IBM WEBSPHERE APPLICATION SERVER CLUSTER

Python programming Testing

Tizen SDK Annual Report Key Improvements. Changseok Oh (Samsung), Yeongkyoon Lee (S-Core)

ABAP Debugging Tips and Tricks

Oracle vs. SQL Server. Simon Pane & Steve Recsky First4 Database Partners Inc. September 20, 2012

Sonian Getting Started Guide October 2008

Approach of Unit testing with the help of JUnit

Realization of Inventory Databases and Object-Relational Mapping for the Common Information Model

Ensim WEBppliance 3.0 for Windows (ServerXchange) Release Notes

Installation Documentation Smartsite ixperion 1.3

Salesforce Knowledge Base Sandbox Configuration Guide

Data Center Virtualization and Cloud QA Expertise

Informatica Data Director Performance

Load testing with. WAPT Cloud. Quick Start Guide

SQL Server 2005: Report Builder

Review of Mobile Applications Testing with Automated Techniques

Automated Integration Testing & Continuous Integration for webmethods

Guide to Mobile Testing

Multi-Tenancy in SharePoint DD105 Spencer Harbar Enterprise Architect harbar.net

IriScene Remote Manager. Version 4.8 FRACTALIA Software

Grandstream Networks, Inc. UCM6100 Security Manual

Exploratory Testing in an Agile Context

Winning the Battle against Automated Testing. Elena Laskavaia March 2016

Agile Testing Principles and Best Practices. Progress Software, Hyderabad, India

Source Code Management for Continuous Integration and Deployment. Version 1.0 DO NOT DISTRIBUTE

Smartphone Pentest Framework v0.1. User Guide

Automating Linux Malware Analysis Using Limon Sandbox Monnappa K A monnappa22@gmail.com

Spark. Fast, Interactive, Language- Integrated Cluster Computing

Define and Configure an Application Request Routing Server Farm

Creating Online Surveys with Qualtrics Survey Tool

Technology Corner. IIS Configuration for Sage ACT! Premium A Review in Pictures

HGC SUPERHUB HOSTED EXCHANGE

Transcription:

Automated Testing with Python assertequal(code.state(), happy ) Martin Pitt <martin.pitt@canonical.com>

Why automated tests? avoid regressions easy code changes/refactoring simplify integration design tool documentation

Unit test from Apport $ python problem_report.py -v basic creation and operation.... ok writing and re-decoding a big random file.... ok handling of CompressedValue values.... ok reading a report with binary data.... ok write_mime() with key filters.... ok [...] ----------------------------------------------------- Ran 25 tests in 4.889s

Unit tests smallest possible testable portion of the code noninteractive independent from each other no assumptions about environment or privileges small and fast

Integration test from pkgbinarymangler $ test/run -v Installed-Size gets updated... ok language packs are not stripped... ok OEM PPA for main package... ok OEM PPA for main package for blacklisted project... FAIL [...] ========================================================== FAIL: OEM PPA for main package for blacklisted project ---------------------------------------------------------- Traceback (most recent call last): File "test/run", line 379, in test_ppa_oem_main_blacklisted self.assert_( locale/fr/lc_messages/vanilla.mo in out) AssertionError ---------------------------------------------------------- Ran 12 tests in 91.783s FAILED (failures=1)

Integration tests end-to-end testing of larger scenarios more expensive reasonable assumptions about environment should still be mostly noninteractive

Python unittest structure 1 i m p o r t c o u n t e r 2 i m p o r t u n i t t e s t 3 4 c l a s s CounterTest ( u n i t t e s t. TestCase ) : 5 d e f setup ( s e l f ) : 6 s e l f. c = c o u n t e r. Counter ( ) 7 s e l f. w o r k d i r = t e m p f i l e. mkdtemp ( ) 8 9 d e f teardown ( s e l f ) : 10 s h u t i l. r m t r e e ( s e l f. w o r k d i r ) 11 12 d e f t e s t f o o ( s e l f ) : 13 #... 14 15 # main 16 u n i t t e s t. main ( )

Python unittest test cases 1 d e f t e s t i n i t ( s e l f ) : 2 Counter i s i n i t i a l i z e d w i t h 0 3 s e l f. a s s e r t E q u a l ( s e l f. c. count ( ), 0) 4 5 d e f t e s t i n c ( s e l f ) : 6 Counter. i n c ( ) adds +1 7 s e l f. c. i n c ( ) 8 s e l f. a s s e r t E q u a l ( s e l f. c. count ( ), 1) 9 10 d e f t e s t s t r ( s e l f ) : 11 Counter s t r i n g f o r m a t t i n g 12 s e l f. c. s e t ( 2 3 ) 13 s e l f. a s s e r t E q u a l ( x%s y % s e l f. c, x23y )

Errors and corner cases 1 d e f t e s t n o n i n t ( s e l f ) : 2 R e j e c t s non i n t e g e r s 3 s e l f. a s s e r t R a i s e s ( TypeError, s e l f. c. s e t, 1. 5 ) 4 5 d e f t e s t h u g e ( s e l f ) : 6 S u p p o r t s a r b i t r a r i l y l a r g e numbers 7 s e l f. c. s e t ( s y s. maxint ) 8 s e l f. c. i n c ( ) 9 s e l f. a s s e r t ( s e l f. c. count ( ) > s y s. maxint ) 10 s e l f. a s s e r t R a i s e s ( TypeError, s e l f. c. s e t, 1. 5 ) 11 12 d e f t e s t n o n n e g ( s e l f ) : 13 Can t count below z e r o 14 s e l f. c. i n c ( ) 15 s e l f. c. dec ( ) # s h o u l d be 0 now 16 s e l f. a s s e r t R a i s e s ( V a l u e E r r o r, s e l f. c. dec ) 17 # d e f i n e d v a l u e a f t e r e r r o r 18 s e l f. a s s e r t E q u a l ( s e l f. c. count ( ), 0)

Test-friendly code avoid hardcoded external addresses use proper abstractions (dbapi2, complete URLs, logic vs. GUI) break complex tasks into separate methods

Techniques JFDI! locality for unit tests: mock objects locality for integration tests: files: mini-chroots with mkdtemp() databases: sqlite :memory: network: SimpleHttpServer on localhost packages: $APT CONFIG devices: loop, $SYSFS PATH UI testing: event synthesis, xvfb

doctest 1 d e f f a c t o r i a l ( n ) : 2 Return t h e f a c t o r i a l o f n, an e x a c t i n t e g e r >= 0. 3 4 I f t h e r e s u l t i s s m a l l enough to f i t i n an i n t, 5 r e t u r n an i n t. E l s e r e t u r n a l o n g. 6 7 >>> f a c t o r i a l ( 0 ) 8 1 9 >>> f a c t o r i a l ( 5 ) 10 120 11 12 N e g a t i v e v a l u e s a r e not a l l o w e d : 13 14 >>> f a c t o r i a l ( 1) 15 Traceback ( most r e c e n t c a l l l a s t ) : 16... 17 V a l u e E r r o r : n must be >= 0 18 19 20 n = 0 #...

Need more power? Mock objects: python-mock Comprehensive UI testing: mago kvm

References http://en.wikipedia.org/wiki/unit testing http://docs.python.org/library/unittest.html test suites of Apport, Jockey, pkgbinarymangler, apt