Unit Testing Strategies

Similar documents
20-30 minutes, can be used within a longer activity

Seven Deadly Sins of Debugging

Java course - IAG0040. Unit testing & Agile Software Development

PHPUnit and Drupal 8 No Unit Left Behind. Paul Mitchum

Improved Software Testing Using McCabe IQ Coverage Analysis

Testing Rails. by Josh Steiner. thoughtbot

Co-Presented by Mr. Bill Rinko-Gay and Dr. Constantin Stanca 9/28/2011

Previously, you learned the names of the parts of a multiplication problem. 1. a. 6 2 = 12 6 and 2 are the. b. 12 is the

Code Qualities and Coding Practices

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

Testing Metrics. Introduction

case study Coverity Maintains Software Integrity of Sun Microsystems Award-Winning Storage Products

Continuous integration End of the big bang integration era

The 5 P s in Problem Solving *prob lem: a source of perplexity, distress, or vexation. *solve: to find a solution, explanation, or answer for

Common Mistakes in Data Presentation Stephen Few September 4, 2004

The Top 3 Common Mistakes Men Make That Blow All Their Chances of Getting Their Ex-Girlfriend Back Which of these mistakes are you making?

Case Study Writers Make

15 Most Typically Used Interview Questions and Answers

Guidelines for the Development of a Communication Strategy

A Glossary of Scrum / Agile Terms

Top 10 Spreadsheet Risks. Excel Community Blog series summary SAMPLE

Software Testing. Knowledge Base. Rajat Kumar Bal. Introduction

>> My name is Danielle Anguiano and I am a tutor of the Writing Center which is just outside these doors within the Student Learning Center.

An Example Checklist for ScrumMasters

Options on Beans For People Who Don t Know Beans About Options

Guide to Writing a Project Report

Interview with David Bouthiette [at AMHI 3 times] September 4, Interviewer: Karen Evans

Solving the Rubik's Revenge (4x4x4) Home Pre-Solution Stuff Step 1 Step 2 Step 3 Solution Moves Lists

Jazz Source Control Best Practices

Principles of Modeling: Real World - Model World

Part II. Managing Issues

Learn How to Create and Profit From Your Own Information Products!

Why do we stereotype?

QaTraq Pro Scripts Manual - Professional Test Scripts Module for QaTraq. QaTraq Pro Scripts. Professional Test Scripts Module for QaTraq

Demonstrating a DATA Step with and without a RETAIN Statement

The Dirty Little Secret of Software Pricing

A: I thought you hated business. What changed your mind? A: MBA's are a dime a dozen these days. Are you sure that is the best route to take?

International Undergraduates Classroom Experiences

Kafka & Redis for Big Data Solutions

But have you ever wondered how to create your own website?

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

Test Driven Development Part III: Continuous Integration Venkat Subramaniam

Working with forms in PHP

Fluke 89-IV & 189 Event Logging

Why Don't They Leave? Domestic Violence/Abuse

The State of Split Testing Survey Analysis

The Doctor-Patient Relationship

Introduction to Public Safety Project Management. Table of Contents. Introduction to Public Safety Project Management

Avoid the biggest pitfalls with Video Conferencing

XP & Scrum. extreme Programming. XP Roles, cont!d. XP Roles. Functional Tests. project stays on course. about the stories

MOST FREQUENTLY ASKED INTERVIEW QUESTIONS. 1. Why don t you tell me about yourself? 2. Why should I hire you?

What is a parabola? It is geometrically defined by a set of points or locus of points that are

10 ways to screw up with Scrum and XP Welcome! 1.Sit near the front please! 2.Are you using Scrum or XP? If so grab 3 colored ballots from the stage.

Time Management. Randy Pausch Carnegie Mellon University

Anyone Can Learn PROC TABULATE

How To Test Your Code

Continuous Integration Optimizing Your Release Management Process

Adopting Agile Testing

Unit testing with JUnit and CPPUnit. Krzysztof Pietroszek

Upping the game. Improving your software development process

How to Outsource Without Being a Ninnyhammer

Appendix 1: Adaptable Templates

Securing the PHP Environment with PHPSecInfo. Ed Finkler

101 IELTS Speaking Part Two Topic cards about sports, hobbies and free time A- Z

Contractor Interview Questions: Summary

In all sorts of work and personal situations, you come across people

Lomira School District Comment Analysis October 14, 2013

GOD S BIG STORY Week 1: Creation God Saw That It Was Good 1. LEADER PREPARATION

Continuous Integration

Developing and Delivering a Winning Investor Presentation

Aligning Customer Expectations. In the Complex World of Magento

Using Adaptive Web Design to Increase E-Commerce Sales & Lead Generation

WEALTH. The Great Secret of the Ages

Quality Meets the CEO

Continuous Integration

Role of husbands and wives in Ephesians 5

Neutrality s Much Needed Place In Dewey s Two-Part Criterion For Democratic Education

Recurring Work Orders - Overview. Purpose. Generating Tasks

Your First Web Page. It all starts with an idea. Create an Azure Web App

Total Indicated Runout, Version 2

PHP Debugging. Draft: March 19, Christopher Vickery

Modern Science vs. Ancient Philosophy. Daniel Gilbert s theory of happiness as presented in his book, Stumbling on Happiness,

Transcription:

Unit Testing Strategies SEATTLE PORTLAND AUSTIN BALTIMORE ORLANDO D. Keith Casey Jr Chief Stuff Breaker/Blue Parabola

Overview What is Unit Testing? What's the point of Unit Testing? Our Holy Grail Useless Unit Testing Deciding where to write Unit Tests Some Useful Unit Tests

So.. who are you?. Chief Stuff Breaker, Blue Parabola I break stuff with the underlying goal of understanding and making it better Help organize php tek, former contrib to the DCPHP, now with AustinPHP & Flash Web2project Head Custodian

What is Unit Testing? Unit Testing is the process where individual blocks, functions, methods, or units of code are tested individually A pre-determined set of input is used to generate an output which is compared against an expected output Different from Integration Testing where the interaction between structures is tested

What is Unit Testing? In plain terms: Unit Testing lets you know when your code breaks. Not if, when. Great when you're refactoring and the guts change but the result shouldn't Great for reproducing errors when you know particular inputs break the code

What is our goal? 100% code coverage It means that we have a test for every line of code and all of our code works exactly as designed For lack of a better term, it's perfect Right?

Bzzt. Wrong Bozo. It doesn't mean that at all.

Code Coverage 100% code coverage means that when the entire sum of all your tests are run, every line is executed at least once And it means nothing else* * Except in TDD

class Calc { public function add($a, $b){ class TestCalc extends PHPUnit_Testcase { return $a+$b; public function testadd() { $calc = new Calc(); assertequals(5, $calc->add(2, 3)); assertequals(0, $calc->add(1,-1));

class Calc { public function add($a, $b){ $_SESSION['count']++; $_SESSION['doh'] = true; class TestCalc extends PHPUnit_Testcase { public function testadd() { $calc = new Calc(); return $a+$b; assertequals(5, $calc->add(2, 3)); assertequals(0, $calc->add(1,-1));

So what's the point? Code Coverage in itself is a useless metric It does not mean your code is done, perfect, bugfree, good, bad, or anything else.. No matter what your PHB (or the Rails community) says We need to move past code coverage..

What do we replace it with? Useful Tests A test is useful if it tests a new set of conditions not previously covered A test that reproduces a previous bug or error state and demonstrates its resolution is ++good It must test something non-trivial

class Calc { public function add($a, $b){ class TestCalc extends PHPUnit_Testcase { return $a+$b; public function testadd() { $calc = new Calc(); assertequals(5, $calc->add(2, 3)); assertequals(0, $calc->add(1,-1));

class Calc { public function add($a, $b){ class TestCalc extends PHPUnit_Testcase { return $a+$b; public function testadd() { $calc = new Calc(); assertequals(5, $calc->add(2, 3)); assertequals(0, $calc->add(1,-1)); How in the world is this non-trivial!?

What should we avoid? Trivial Tests Trivial Tests contribute to code rot, bad inertia, and generally make you and your team testresistant If you're writing these tests, just stop it or tigers will eat you Seriously, I'll arrange it

How should we represent this? Useful Tests / Total Tests (higher is better?) Trivial Tests / Total Tests (lower is better?) Useful Tests / Trivial Tests (higher is better, but divide by zero is ideal?) Don't ask me

So which tests do we need? Code is Communication Every line you type communicates Instructions to the computer, intentions to your team, and explanations to the you of six months from now Unit Tests must be treated the same

When we write tests.. We have to balance many requirements The customer wants results The boss just wants it done We want confidence in current and future changes

So we have to choose carefully First, look towards new functionality A scary codebase is no reason to let your problem grow Start testing the new pieces now, figure it out and even if you never get to the backlog, things are getting better We communicate a new expectation

In web2project.. Helper & Formatting functions These were completely new to the system and designed to generate specifically defined blocks of html & data Building tests for these let us prototype, expand, and use them throughout the system with confidence

Testing new functionality This offers some interesting options You can make sure new code adheres to new QA processes like coding standards, reviews, etc As you figure out how to test the new pieces, something else will emerge..

So we have to choose carefully Next, look towards core functionality If you have classes or functions used constantly and all over the place, add tests for those next We communicate stability and intention The most important reason is eliminating the pseudo-bogus bug reports

In web2project.. Core security, filtering, and formatting As we built our Helpers, we found that most were using filtered input data & combining the results of core functions Testing core functions supported both the new code (Helpers) and numerous places throughout the system

Testing core functionality Gives us some interesting perspective New modules & functionality benefits immediately, and even more as refactoring occurs We get free testing all over the system with a relatively small amount of effort and a new pattern will emerge..

So we have to choose carefully Finally, test problematic functionality Your tests in other areas will highlight the annoying parts of the system Annoying can be where the most bugs are or it could be what is changing the most, it doesn't matter

In web2project.. Trevor Morse Canadian but still an okay guy By sorting our issue reports by module, two modules stood out as having nearly 50% of the bugs, the next closest ~5% With the confidence from the other core functions, adding complex tests became possible

But we have another opportunity To report a bug, we need a test While bug reports without tests aren't ignored, they are considered after the testable ones The Zend Framework has this recommendation The team communicates problems

Broken Window Theory James Q Wilson & George L Kelling You set the standard for your team, group, project, neighborhood As that standard lower, everyone's expectations drop & behavior changes As that standard raises, expectations improve & behavior change http://en.wikipedia.org/wiki/broken_windows_theory http://pragprog.com/the-pragmatic-programmer/extracts/software-entropy

Recap We defined Unit Testing We criticized the Holy Grail of 100% Code Coverage We talked about the difference between Useful and Trivial Tests We covered that code whether project or tests is communication We talked about implementing tests on a project first for new functionality, then core, then pain points. I threatened you with tigers

Questions? D. Keith Casey Jr, Chief Stuff Breaker keith@blueparabola.com Twitter/Skype/AIM/IRC: caseysoftware