Adding automated tests to existing projects

Similar documents
Automated Testing of Large Projects With Perl. Andy Lester

TESTING TOOLS. Standard Suite

An Introduction to Unit Testing

runs all the testscripts named as arguments and checks standard output for the expected strings in TAP format.

subtest $builder->subtest($name,

# Rather than print STDERR "# here s what went wrong\n" diag("here s what went wrong");

AHHHHHHH!!!! NOT TESTING! Anything but testing! Beat me, whip me, send me to Detroit, but don t make me write tests!

# use a BEGIN block so we print our plan before MyModule is loaded BEGIN { plan tests => 14, todo => [3,4] }

PERL DATABASE ACCESS

General Coding Standards

# Rather than print STDERR "# here's what went wrong\n" diag("here's what went wrong");

Test Driven Development TDD

Object Oriented Software Design - I


Test Driven Development and Refactoring. CSC 440/540: Software Engineering Slide #1

Kent Beck describes a five-step cycle for test-driven development [Beck, 2002, p 7]. The steps are:

1. Introduction. 2. Scalar Data

A Crash Course in Perl5

Practical Objects: Test Driven Software Development using JUnit

Module::Pluggable - automatically give your module the ability to have plugins

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees.

1 Getting used to Python

COURSE 11 DESIGN PATTERNS

3 Continuous Integration 3. Automated system finding bugs is better than people

Analysis of the Test Driven Development by Example

The main differences with other open source reporting solutions such as JasperReports or mondrian are:

COMS 3101 Programming Languages: Perl. Lecture 6

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing

Kaivos User Guide Getting a database account 2

Developing Online Databases and Serving Biological Research Data

COPYRIGHTED MATERIAL. Index

Lab Exercise Test First using JUnit

Test Driven Development For Embedded C (Pragmatic Programmers) PDF

Software Engineering Testing and Debugging Testing

PHP for PL/SQL Developers. Lewis Cunningham JP Morgan Chase

CS 370 The Pseudocode Programming Process D R. M I C H A E L J. R E A L E F A L L

CSE 403 Lecture 13. Black/White-Box Testing. Reading: Software Testing: Principles and Practices, Ch. 3-4 (Desikan, Ramesh)

6.170 Laboratory in Software Engineering Eclipse Reference for 6.170

Some good development practices (not only in NLP)

A Field Guide To The Perl Command Line. Andy Lester

The Perl Debugger. Avoiding Bugs with Warnings and Strict. Daniel Allen. Abstract

csc444h: so(ware engineering I matt medland

Agile Manifesto & XP. Topics. Rapid software development. Agile methods. Chapter ) What is Agile trying to do?

Java Programming. Computer Science 112

Control Structures. Important Semantic Difference

MEDIA COMPUTATION DRJAVA. Lecture 11.3 November 7, 2008

Shared Variables and Interference

User Scripting April 14, 2018

print STDERR "This is a debugging message.\n";

How technical excellence helps in LeSS adoption. Anton Bevzuk Dodo Pizza Chief Agile Officer

COMP 354 TDD and Refactoring

Testing. Prof. Clarkson Fall Today s music: Wrecking Ball by Miley Cyrus

CMSC 132: OBJECT-ORIENTED PROGRAMMING II

Perl Mysql Dbi Insert Last Id >>>CLICK HERE<<<

CS Homework 7 p. 1. CS Homework 7. Problem 1 - START THIS A.S.A.P. (in case there are PROBLEMS...)

Mock Objects and Distributed Testing

Most of the class will focus on if/else statements and the logical statements ("conditionals") that are used to build them. Then I'll go over a few

Samsung Galaxy S3 Repair Video Calling Not Working

Unit Testing with JUnit and CppUnit

Reengineering II. Transforming the System

Program Structure I. Steven M. Bellovin November 8,

Testing! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 6!

Pontificating on Perl Profiling. Lisa Hagemann VP Engineering, Dyn Inc. twitter.com/lhagemann twitter.com/dyninc

xtreme Programming (summary of Kent Beck s XP book) Stefan Resmerita, WS2015

EECS 4313 Software Engineering Testing

Unit Testing In Python

BBC Learning English Face up to Phrasals Bob & Jackie's Chemistry Project

Perl (5 Days Content)

DESIGN AS RISK MINIMIZATION

Testing! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 6!

Lab 7 Macros, Modules, Data Access Pages and Internet Summary Macros: How to Create and Run Modules vs. Macros 1. Jumping to Internet

Build Meeting Room Management Website Using BaaS Framework : Usergrid

Access Intermediate

Unit Testing as Hypothesis Testing

Devel::NYTProf. Perl Source Code Profiler

Software Engineering I (02161)

CSSE 220 Day 3. Check out UnitTesting and WordGames from SVN

Automated testing in Agile SW development

Devel::Cover - An Introduction

4 + 4 = = 1 5 x 2 = 10

PERL Scripting - Course Contents

This is a list of questions and answers about Unicode in Perl, intended to be read after perlunitut.

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Clergy and Chancery, Parish and School Staff. Tom Hardy, Director, Office of Information Technology

Testing, code coverage and static analysis. COSC345 Software Engineering

A Tour of Perl Testing

SQLITE PERL TUTORIAL

MITOCW watch?v=9h6muyzjms0

Validate and Protect Data

Chapter 11, Testing, Part 2: Integration and System Testing

CVS. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 21

Fortunately, you only need to know 10% of what's in the main page to get 90% of the benefit. This page will show you that 10%.

Program Verification! Goals of this Lecture! Words from the Wise! Testing!

Chapter 11, Testing, Part 2: Integration and System Testing

What is OneNote? The first time you start OneNote, it asks you to sign in. Sign in with your personal Microsoft account.

Microsoft Office Training Skills 2010

Read & Download (PDF Kindle) Data Structures And Other Objects Using Java (4th Edition)

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Devel::NYTProf. Perl Source Code Profiler. Tim Bunce - July 2009 Screencast available at

Eclipse Summit Europe Summary

Transcription:

Adding automated tests to existing projects

Adding automated tests to existing projects

Problems of programming

Code is buggy Human testing doesn't scale Human time is too expensive We test manually, intermittently, or not at all

Human testing doesn't scale

Bugs keep reappearing.

We're afraid to change the code.

Changes in code here break code over there.

New code takes too long to write.

Our code is poorly designed (especially the APIs).

Promises Faster coding Fewer bugs Prevent regressions Improved confidence in the code Refactor with impunity Documentation & examples for free

Test-first bug fixing Don't reach for the debugger prove was made for test-first Once the bug is fixed, it's unlikely to regress

Overview of Perl testing What did we just use? Lightweight No Java-like structure necessary Test::Harness, Test::More & TAP prove

Test-first new code Logical extension of bug fixing Define the API Test anti-examples Write docs as we write new functionality Code/docs/tests must all agree

What makes a good test?

Right-BICEP Is it right? Boundaries? Inverse conditions? Cross-checking Error conditions? Performance

Ten cool tests you can write today

No default passwords Make sure there are no defaults use constant USER => 'SYS'; use constant PASS => 'CHANGE_ON_INSTALL'; my $dbh = DBI->connect( $mydb, USER, PASS ); my $sth = $dbh->prepare( "select 1 from dual" ); my $rc = $sth->execute; isnt( $rc, 0, 'SYS user doesn't have default PW' );

All ISBNs valid Get all ISBNs and run them through a validator my $sth = $dbh->prepare( "select ISBN from BOOK" ); $sth->execute(); my $bad; while ( my $row = $sth->fetch ) { $isbn = new Business::ISBN( $row->[0] ); if (!$isbn->is_valid ) { fail( "Invalid ISBN(s) found" ) unless $bad++; diag( "$row->[0] is invalid" ); } } pass( "No bad ISBNs found" ) unless $bad;

Use warnings/strict First find all our files # Find all Perl files, but don t look in CVS my $rule = File::Find::Rule->new; $rule->or( $rule->new->directory-> name('cvs')->prune->discard, $rule->new->file->name( '*.pl','*.pm','*.t' )); my @files = $rule->in( $base ); check( $_ ) for @files;

Use warnings/strict Check for warnings & strict sub check { my $filename = shift; my $dispname = File::Spec->abs2rel( $filename, $base ); local $/ = undef; open( my $fh, $filename ) or return fail( "Couldn't open $dispname: $!" ); my $text = <$fh>; close $fh; like( $text, qr/use strict;/, "$dispname uses strict" ); like( $text, qr/use warnings; perl -w/, "$dispname uses warnings" ); } # check()

All.pm have.t Get a list of.pm files and then... sub check { my $filename = shift; my $tname = $filename; $tname =~ s/ \.pm \Z /.t /x or die "Only send me.pm files, please"; ok( -s $tname, "$filename has a test file" ); } # check()

All HTML valid Get a list of HTML files, and... for my $filename ( @files ) { open( my $fh, $filename ) or fail( "Couldn't open $filename" ), next; my $text = do { local $/ = undef; <$fh> } local $/ = undef; close $fh; my $lint = HTML::Lint->new; $lint->only_types( HTML::Lint::Error::STRUCTURE ); html_ok( $lint, $text, $dispname ); } diag( "$html HTML files" );

Installed modules Create a hash of modules you must have my %requirements = ( # 0 means we don't care 'Business::ISBN' => 0, 'Carp::Assert' => '0.17', 'Carp::Assert::More' => '1.10', 'Date::Calc' => 0, 'Date::Manip' => 0, 'DateTime' => '0.20', 'DB_File' => '1.808', 'Exporter' => '5.562', 'File::Spec' => '0.82', 'File::Temp' => '0.13',... );

Installed modules... and then check for them. for my $module ( sort keys %requirements ) { my $wanted = $requirements{ $module }; if ( use_ok( $module ) ) { if ( $wanted ) { my $actual = $module->version; cmp_ok( $actual,'>=',$wanted, $module ); } else { pass( "$module loaded" ); } } else { fail( "Can't load $module" ); } } # for keys %requirements

sprintf works PHP broke sprintf // sprintf broke between PHP 4.2.3 and 4.3.0 require( "Test.php" ); plan( 4 ); diag( "PHP Version ". phpversion() ); $masks = Array( "%-3.3s", "%.3s", "%-.3s" ); $str = "abcdefg"; foreach ( $masks as $mask ) { $result = sprintf( "[$mask]", $str ); is( $result, "[abc]", "[$mask]" ); }

No embedded tabs Find and print any embedded tab files sub check { my $fname = shift; open( my $fh, "<", $fname ) or die "$fname: $!\n"; my $bad; while ( my $line = <$fh> ) { if ( $line =~ /\t/ ) { fail( "$fname has tabs" ) unless $bad++; diag( "$.: $line" ); } } # while pass( "$fname is tab-free" ) unless $bad; } # check

All POD is OK Test::Pod makes it terribly simple use Test::More; use Test::Pod 1.00; all_pod_files_ok();

All functions have POD Test::Pod::Coverage makes it terribly simple use Test::More; use Test::Pod::Coverage 1.04; all_pod_coverage_ok();

For the managers Make tests & docs part of code standards Code without tests is not complete Tests & docs are part of code reviews All three are reviewed at once.

For the managers Track and post metrics Test counts over time are reassuring for you and for programmers Trends matter Individual numbers don't

For the managers Make testing part of hiring "What experience do you have with automated testing?" "What could go wrong with this code? How could you test for it?"

Best practices Code/tests/docs must all agree Continuous integration Don't worry about test execution time Do worry about programmer time It's an investment, albeit a pretty cheap one.

Best practices Bug tracking system & source control Module::Starter to get things going Devel::Cover to check test coverage Tie tests & commits to specific tickets

Best practices Test anything that ever goes wrong Add tests every time you fix a bug Treat failed tests like an oil light

Recommended resources Perl Testing: A Developer's Notebook, by Ian Langworth & chromatic Perl Best Practices, by Damian Conway Pragmatic Unit Testing In Java With JUnit, by Andrew Hunt & Dave Thomas Test-Driven Development, by Kent Beck Refactoring, by Martin Fowler

Thanks for coming