Or ways to enhance coding enjoyment, productivity and, most of all, preserve your sanity. Nicolas Connault Web developer Moodle HQ February 19 th 2008.

Slides:



Advertisements
Similar presentations
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Advertisements

Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Test-Driven Development. Why Testing is Important? “If you don’t have tests, how do you know your code is doing the thing right and doing the right thing?”
Adding scalability to legacy PHP web applications Overview Mario A. Valdez-Ramirez.
Test-Driven Development and Refactoring Project 3 Lecture 1 CPSC 315 – Programming Studio Fall 2009.
Individuals and interactions
Individuals and interactions
Convergent Newsroom Schedule and Road Map. Unify the User Interface Design Development of the user interface was done in parallel, so the parts need.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
Agile Testing with Testing Anywhere The road to automation need not be long.
By: Taylor Helsper.  Introduction  Test Driven Development  JUnit  Testing Private Methods  TDD Example  Conclusion.
Introduction to Continuous Integration Mike Roberts.
By: Taylor Helsper.  Introduction  Test Driven Development  JUnit  TDD Example  Conclusion.
TDD,BDD and Unit Testing in Ruby
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
Test Driven Development TDD. Testing ”Testing can never demonstrate the absence of errors in software, only their presence” Edsger W. Dijkstra (but it.
Introduction to Unit Testing Jun-Ru Chang 2012/05/03.
1 Software Testing (Part-II) Lecture Software Testing Software Testing is the process of finding the bugs in a software. It helps in Verifying and.
© 2012 IBM Corporation Rational Insight | Back to Basis Series Chao Zhang Unit Testing.
Chapter 8 – Software Testing Lecture 1 1Chapter 8 Software testing The bearing of a child takes nine months, no matter how many women are assigned. Many.
Testing in Extreme Programming
Design and Programming Chapter 7 Applied Software Project Management, Stellman & Greene See also:
The First in GPON Verification Classic Mistakes Verification Leadership Seminar Racheli Ganot FlexLight Networks.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Chapter 8 – Software Testing Part 2 1Chapter 8 Software testing.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
COMP 121 Week 1: Testing and Debugging. Testing Program testing can be used to show the presence of bugs, but never to show their absence! ~ Edsger Dijkstra.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
CSC 395 – Software Engineering Lecture 10: Execution-based Testing –or– We can make it better than it was. Better...faster...agiler.
Future Media  BBC MMXI TDD at the BBC David Craddock, Jack Palfrey and Tom Canter.
Sofia Bulgaria Summer School IST eXPERT: Best Practice on e-Project Development 30 June - 2 July 2003 eXtreme programming.
Software Construction Lecture 18 Software Testing.
First BlueJ Day Houston, 2006 Unit Testing with BlueJ Bruce Quig Deakin University.
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
TEST-1 6. Testing & Refactoring. TEST-2 How we create classes? We think about what a class must do We focus on its implementation We write fields We write.
CS5103 Software Engineering Lecture 02 More on Software Process Models.
Test-Driven Development Eduard Miric ă. The problem.
Extreme programming (XP) Variant of agile Takes commonsense practices to extreme levels © 2012 by Václav Rajlich1.
Refactoring and Integration Testing or Strategy, introduced reliably by TDD The power of automated tests.
Automated Testing in Sakai Testing applications and services in isolation and in context Josh Holtzman, UC Berkeley David Haines, University of Michigan.
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
Observing the Current System Benefits Can see how the system actually works in practice Can ask people to explain what they are doing – to gain a clear.
CS 5150 Software Engineering Lecture 22 Reliability 3.
CS223: Software Engineering Lecture 18: The XP. Recap Introduction to Agile Methodology Customer centric approach Issues of Agile methodology Where to.
Northwest Arkansas.Net User Group Jay Smith Tyson Foods, Inc. Unit Testing nUnit, nUnitAsp, nUnitForms.
Beginning Software Craftsmanship Brendan Enrick Steve Smith
INTRODUCTION CSE 470 : Software Engineering. Goals of Software Engineering To produce software that is absolutely correct. To produce software with minimum.
Software Engineering Lecture 11 Software Testing Presenter: Josef Hallberg 1.
Software Development. The Software Life Cycle Encompasses all activities from initial analysis until obsolescence Analysis of problem or request Analysis.
TDD Unit tests from a slightly different point of view Katie Dwyer.
What is a Functional Spec?  Defines what the functionality will be NOT how it will be implemented  Describes features of the software product product's.
1 © Agitar Software, 2007 Automated Unit Testing with AgitarOne Presented by Eamon McCormick Senior Solutions Consultant, Agitar Software Inc. Presented.
Software Testing Kobla Setriakor Nyomi Faculty Intern (Programming II)
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Software Development.
Unit Testing.
Smalltalk Testing - SUnit
Integrate Agile Testing into the Process
Software Testing An Introduction.
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
Chapter 8 – Software Testing
Software Testing.
Quality Control in the dCache team.
History, Characteristics and Frameworks
Testing and Test-Driven Development CSC 4700 Software Engineering
Software Testing & Quality Management
Baisc Of Software Testing
Refactoring.
CS 240 – Advanced Programming Concepts
ENERGY 211 / CME 211 Lecture 27 November 21, 2008.
Presentation transcript:

Or ways to enhance coding enjoyment, productivity and, most of all, preserve your sanity. Nicolas Connault Web developer Moodle HQ February 19 th 2008 Unit testing

2 Lecture Outline Introduction to Unit Testing Development principles Unit Test Frameworks Unit tests for legacy code Resources

3 Introduction to Unit Testing Overview: Why write unit tests? Why not? What are bugs? What unit tests won't do for you

4 Introduction to Unit Testing Why write Unit Tests? Clean, bug-free, documented code Quality software: less complaints Coding simplicity: less stress Why not? Not enough time! Overview

5 Introduction to Unit Testing The less tests, the more bugs The more bugs, the more complaints The more complaints, the more stress The more stress, the less tests we write Overview

6 Introduction to Unit Testing Can we write bug-free code? Overview ? ? ? ? ? ? ?

7 Introduction to Unit TestingOverview What is a bug? An unwanted feature (memory leak, feature creep etc.) A "broken" feature A misunderstood feature (by the client or the coder) "It's not a bug, it’s a feature!"

8 Introduction to Unit TestingOverview What Unit Tests don’t do: Performance issues Integration errors User interface issues

9 Introduction to Unit TestingStatistics According to some very reliable sources, programmers tend to spend over 80% of their working time looking for causes of bugs in existing code, 15% fixing these bugs, and 5% designing and developing new code. (source: N.Connault's astute observations, 2008).

10 Introduction to Unit TestingCollateral Damage Code Library 1Code Library 2 Identify Bug Fix bug Patch library 1 Test library 1 Result: Waste of time NEW HIDDEN BUG !!! Dependencies

11 Introduction to Unit TestingSolution Code Library 1Code Library 2 Identify Bug Fix bug Patch libraries Test all libraries Result: Better code When all tests pass... Dependencies

12 Coding principles that apply to unit testing...

13 Coding principles If you don't know why your modification fixed a bug, Ignorance is the enemy you're almost guaranteed to be the creator of at least one new bug

14 Coding principles Development and testing are not separate tasks Holistic development

15 Coding principles The goal of programming is to reduce the amount of repetitive work and the number of simple decisions humans need to make. Testing code is repetitive, and it is usually simple. Tests should be automated. Automation

16 Coding principles Each unit test must test a single unit of code. A unit of code is usually a simple function or a simple method. Isolation Example of an overloaded function: solveWorldHunger(money)

17 Coding principles One unit test must never affect another. The order in which they are run must be absolutely inconsequential Independence

18 Coding principles When you need new functionality, first write a failing unit test, then implement the new code. Test-driven development

19 Coding principles Never introduce bugs in your unit tests. Write them with the same rigour as with your regular code. Reliability

20 Coding principles Write mock objects for: Objects whose behaviour is non-deterministic (news feed)‏ Objects that are complex/difficult to set up Objects that are slow Objects that have or are a User Interface Objects whose behaviour is hard to trigger Objects that haven't yet been implemented Mock objects

21 Coding principles NEVER, NEVER, NEVER commit code if any unit test fails !!! Golden Rule

22 Coding principles Test boundary conditions as much as is possible and reasonable, including heavy load conditions. Thoroughness

23 Coding principles Don't write tests for code that will obviously never fail Prioritise

24 Questions and answers ?+!

25 Unit test Frameworks Automate the generation of unit testing code Simplify the entire process Provide advanced testing features (mock objects, fancy reports, expectations etc…) Advantages

26 Unit Tests in legacy code Too big a job to “catch up” all at once Create unit tests to verify bug reports Use unit tests to fix bugs Refactor code when needed Commit bug fix when all unit tests pass

27 Resources Andrew Hunt and David Thomas. Pragmatic Unit Testing in Java with JUnit. The Pragmatic Programmers, LLC, Raleigh, NC, and Dallas, TX, Venkat Subramaniam and Andy Hunt. Practices of an Agile Developer working in the Real World, The Pragmatic Bookshelf,