Testing and Debugging CS221 – 2/13/09. Airline Program.

Slides:



Advertisements
Similar presentations
Testing Relational Database
Advertisements

Software Testing. Quality is Hard to Pin Down Concise, clear definition is elusive Not easily quantifiable Many things to many people You'll know it when.
Test process essentials Riitta Viitamäki,
White Box and Black Box Testing Tor Stålhane. What is White Box testing White box testing is testing where we use the info available from the code of.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
Software testing.
Testing and Debugging pt.2 Intro to Complexity CS221 – 2/18/09.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
Test-Driven Development With Visual Studio 2005 Erno de Weerd Info Support.
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
System/Software Testing
Extreme Programming Software Development Written by Sanjay Kumar.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Software Quality Assurance Lecture #8 By: Faraz Ahmed.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 23 Slide 1 Software testing Slightly adapted by Anders Børjesson.
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.
CMSC 345 Fall 2000 Unit Testing. The testing process.
Software Testing.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
What is Software Testing? And Why is it So Hard J. Whittaker paper (IEEE Software – Jan/Feb 2000) Summarized by F. Tsui.
TVAC Electronic Call Sheet System Team HeatWave Summer 2007.
 CS 5380 Software Engineering Chapter 8 Testing.
SOFTWARE TESTING Scope of Testing  The dynamic Indian IT industry has always lured the brightest minds with challenging career.
Testing Basics of Testing Presented by: Vijay.C.G – Glister Tech.
Software Testing Testing types Testing strategy Testing principles.

Software Testing. 2 CMSC 345, Version 4/12 Topics The testing process  unit testing  integration and system testing  acceptance testing Test case planning.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Introduction to Software Testing. Types of Software Testing Unit Testing Strategies – Equivalence Class Testing – Boundary Value Testing – Output Testing.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
Software Construction Lecture 18 Software Testing.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
Chapter 8 Lecture 1 Software Testing. Program testing Testing is intended to show that a program does what it is intended to do and to discover program.
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
Software Engineering Saeed Akhtar The University of Lahore.
Software Quality Assurance and Testing Fazal Rehman Shamil.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
HNDIT23082 Lecture 09:Software Testing. Validations and Verification Validation and verification ( V & V ) is the name given to the checking and analysis.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
Lecturer: Eng. Mohamed Adam Isak PH.D Researcher in CS M.Sc. and B.Sc. of Information Technology Engineering, Lecturer in University of Somalia and Mogadishu.
Today protected access modifier Using the debugger in Eclipse JUnit testing TDD Winter 2016CMPE212 - Prof. McLeod1.
Beginning Software Craftsmanship Brendan Enrick Steve Smith
Software Testing Kobla Setriakor Nyomi Faculty Intern (Programming II)
COTS testing Torbjørn Skramstad.
Unit Testing.
Testing Verification and the Joy of Breaking Code
Testing Tutorial 7.
CS1101X Programming Methodology
Chapter 8 – Software Testing
COTS testing Tor Stålhane.
Introduction to Software Testing
Lecture 09:Software Testing
Testing and Test-Driven Development CSC 4700 Software Engineering
Software testing.
Software Testing & Quality Management
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
CS 240 – Advanced Programming Concepts
Chapter 10: Testing and Quality Assurance
Presentation transcript:

Testing and Debugging CS221 – 2/13/09

Airline Program

Why do we test? To discover logical errors To reduce defects To gain confidence in your system To prove it performs according to specification To reduce risk Testing is a form of Risk Assessment

Creating software is hard Even experienced developers struggle Every line of code can have multiple bugs Every problem has multiple solutions – Some elegant – Some not so elegant Writing simple, working code will always be a challenge Writing code is like writing a book but… – Getting a sentence wrong can cost your business $100M If it was easy, everyone would be doing it!

Not convinced? Consider the complexity of a Boeing 747 Software can’t be subjected to physical analysis and testing Software interactions can’t be ‘seen’ in the real world A modern operating system has 50 million lines of code or more Each line can have 1 or more defects. A 747 has 6 million parts. 3 million of which are fasteners. You tell me: 50MLOC >= Boeing 747?

Testing is just as hard Defect scope varies – Line – Method – Class – Thread – Process – System Difficult to get complete code coverage Impractical to get 100% coverage of paths + data Proving a system is defect free is impossible in the real world

Steps to reduce defects 1.Understand your specification 2.Think first – plan and design your code 3.Mentally step through how your code should work before writing it 4.Manually inspect each block of code 5.Test each block as soon as it is testable 6.Step through complex code with the debugger 7.Write unit tests to automate your testing 8.Use integration tests to test method interactions 9.System test as soon as it is testable 10.Use acceptance tests to demonstrate the system is ready for users

Real world best practices Unit tests on every code change Unit tests + integration tests on every check-in Unit tests + integration tests + system tests on every build Unit tests + integration tests + system tests + acceptance tests on every major milestone Automation makes the difference between an agile team and a team that can’t hit deadlines

Unit Testing Always automated Extremely granular Test each method in isolation if possible Test the class as a whole if necessary JUnit – Java unit testing framework built into Eclipse

Integration Testing Less granular than unit testing Test the interaction of classes to make sure they work well together Integration Test Drivers: You can write your own or use a framework

System Testing Test the entire system with user scenarios in mind For instance: test across multiple application tiers (client, app server, database server) Usually requires some manual testing plus a UI automation test framework Programmatic interfaces can be more easily tested – For instance: a web service vs. a web application.

Acceptance Testing The final testing phase, used as an exit-criteria Used as a means to ‘sign-off’ on a build for a major milestone – Alpha, Beta, Release Defines the criteria by which the software is deemed acceptable to pass the milestone

Black and White Black Box Testing – Test without access to source or program internals – Test the interface from the user perspective – Vary the inputs, see if the outputs match expectations – Interface you are testing could be: Public methods on a class Public interface on a component Network interface User interface – Techniques Automated drivers UI automation tools Dynamic analysis scanning tools Manual testing

Black and White White Box Testing – Test with knowledge of program internals – Use internal knowledge to maximize code coverage – Hit success paths as well as failure paths Techniques – Manual code review – Use the debugger – Instrument the code to force paths – Static analysis tools – Automated drivers

How to make testing easier Comments – On interfaces – On methods – Each parameter – Return values – Describe complex code blocks Defined pre and post conditions – What you expect from your caller – What they should expect from you Simplify – Think of the cost of testing when you develop your code – Simple code is much easier to test than complex

Comment Example

Comments Previous example is probably over-commented In general – Use comprehensive commenting on methods and classes – Line-level comments are not too useful unless the code is very tricky /** comments have a valuable side-effect */

Pre and Post Conditions You can put the post condition in the description and/or comment You can put the pre conditions in comments /** * Given a flight number, delete the appropriate node from the flight list flightNumber A flight number that exists in the flight list NoSuchFlightException */

Pre and Post Conditions

Simplify Statement coverage requires you hit every statement in your source code Branch coverage requires you hit each choice on each branch Path coverage requires you hit every possible combination of statements in your code Every class, method, parameter and conditional statement adds complexity For instance path coverage is 2^N (exponential) where N is the number of conditional statements – 5 if statements = 32 paths – 10 if statements = 1024 paths – 100 if statements = 1.27E30 paths Cyclomatic complexity: Some great tips:

Test Driven Development Develop your test cases first, then implement your code Tests become a part of the specification The code is implemented from the ground-up to pass the tests Any changes to the code requires a re-run of the tests Airline Program example – Design your class/method structure (FlightNode, FlightList, etc) – Stub out your public methods – Create JUnit tests (Add a flight, enqueu a passeger, dequeue a passenger, delete a flight, etc) – As each class is implemented, the tests should start to pass – You know you are done when all the tests pass

Team Roles Developer: Write the code and test to make sure it works Tester: Assess risk to the business if this code was released The days of throwing your code over a wall to a test team are over A developer who cannot test his own code won’t last Modern software development organizations expect high quality code on the first try If you are working with a tester, expect them to find nasty, complex problems before your users do Do not expect a tester to clean up your mess

What should you put in your tests? Focus on hitting each branch – Equivalency classes – Boundary conditions Make sure you understand what results to expect (pass/fail) Path coverage is much harder – leave it to integration and systems testing

Equivalency Classes and Boundaries Equivalency class = A set of inputs that will result in the same branch execution Boundary condition = A set of inputs that will test the edges of a branch condition Together = Pick test inputs that execute each branch using the most extreme edge value

Example

Putting it all together JUnit API Docs Create a JUnit file for each class Use setup() if you need to set up the state of your object Call each of the class methods you want to test Any exception or failed assertion will fail the test Use tearDown() if you need to clean up after testing

Example

Debugging Breakpoints – Line: Stops execution on the specified line – Method: Stops execution on the method – Watchpoint: Stops execution whenever the field is accessed or modified – Exception breakpoint: Stops execution when an exception is thrown – Class load breakpoint: Stops execution when a class is loaded

Debugging Step in: Steps into the method being called Step over: Steps over the method being called Step return: Steps out to the calling method Run to line: Executes until the specified line of code

Debugging Tips Use inspect or variables window to see object values Use breakpoints and step through code that is complex – make sure it works as you expect it You can make changes to the code while debugging but it won’t affect execution till you restart Breakpoints on each branch will quickly tell if you have good branch coverage Use assertions to check boundary conditions/assumptions in your code – Assertions check logical assumptions – Assertions only work if –ea is on compile command line

Key Points Purpose of testing is to understand and reduce risk Unit/Integration/System/Acceptance Use JUnit tests to automate granular testing on methods and classes Black Box vs. White Box Write code with testing cost in mind Test Driven Development – Build your tests first, then implement your solution Use equivalency classes and boundary conditions to drive your testing The debugger is your friend – The more time you spend stepping through code, the better your understanding will be