(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
1 Software Engineering Lecture 11 Software Testing.
Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
(1) Verification Methods CS2110: SW Development Methods Reading: Study Section in the MSD text These slides supplement the textbook – These touch.
Illinois Institute of Technology
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Database Design Concepts Info 1408 Lecture 2 An Introduction to Data Storage.
Testing an individual module
Swami NatarajanJuly 14, 2015 RIT Software Engineering Reliability: Introduction.
Testing Test Plans and Regression Testing. Programs need testing! Writing a program involves more than knowing the syntax and semantics of a language.
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
Fundamentals of Python: From First Programs Through Data Structures
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
System/Software Testing
Fundamentals of Python: First Programs
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Objectives Understand the basic concepts and definitions relating to testing, like error, fault, failure, test case, test suite, test harness. Explore.
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.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Testing Especially Unit Testing. V-model Wikipedia:
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Introduction to Testing 1. Testing  testing code is a vital part of the development process  the goal of testing is to find defects in your code  Program.
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
Design and Programming Chapter 7 Applied Software Project Management, Stellman & Greene See also:
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Introduction to Software Testing. Types of Software Testing Unit Testing Strategies – Equivalence Class Testing – Boundary Value Testing – Output Testing.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
1.  Writing snippets of code that try to use methods (functions) from your program.  Each snippet should test one (and only one) function......by calling.
Systems Life Cycle. Know the elements of the system that are created Understand the need for thorough testing Be able to describe the different tests.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Today’s Agenda  Reminder: HW #1 Due next class  Quick Review  Input Space Partitioning Software Testing and Maintenance 1.
Unit Testing LEVEL GAME.  Create pieces array  Call move or interact  Use getters or return type to verify correct behavior  Test ends (don’t go GameEngine.BOARD_SIZE-1)
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.
JUnit Don Braffitt Updated: 10-Jun-2011.
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
Testing Data Structures Tao Xie Visiting Professor, Peking University Associate Professor, North Carolina State University
1. Black Box Testing  Black box testing is also called functional testing  Black box testing ignores the internal mechanism of a system or component.
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
Testing JUnit Testing. Testing Testing can mean many different things It certainly includes running a completed program with various inputs It also includes.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
Introduction to Exceptions in Java CS201, SW Development Methods.
CS223: Software Engineering Lecture 25: Software Testing.
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
Testing Data Structures
Testing Tutorial 7.
John D. McGregor Session 9 Testing Vocabulary
Dept of Computer Science University of Maryland College Park
Test Automation CS 4501 / 6501 Software Testing
Introduction to JUnit CS 4501 / 6501 Software Testing
Chapter 8 – Software Testing
John D. McGregor Session 9 Testing Vocabulary
John D. McGregor Session 9 Testing Vocabulary
Testing and Test-Driven Development CSC 4700 Software Engineering
Introduction to JUnit CS 4501 / 6501 Software Testing
CS 1111 Introduction to Programming Fall 2018
Coding Concepts (Basics)
Computer Science Testing.
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Section 4: Graphs and Testing
Presentation transcript:

(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture on the topic of testing and verification.

(2) Some Definitions Verification: showing that something meets specifications –We verify “against” something –Important: if you don’t have requirements specifications documented, then you can’t verify! –If behavior is not defined, then what counts as incorrect behavior? Verification can happen on any kind of software work- product –designs, code, etc.

(3) Types of Testing Unit testing –An individual class or function is tested thoroughly –Done as part of coding process –Done by the programmer him/herself –Usually by a test harness (or driver) or using a test-class Integration testing –Multiple parts of a system are combined and tested to see if they work together Acceptance testing –The customer is involved. (Alpha or beta testing)

(4) Lab on Monday/Tuesday The JUnit framework is a tool to help people generate and execute unit tests in a systematic way. Stand-alone and also built into Eclipse Example JUnit test –A class contains a set of test methods –setUp() runs before each test –Methods with name starting with “test…” are run –“assert” methods check a program condition public class CoffeeMakerTest extends TestCase { private CoffeeMaker cm; private Recipe recipe1; public void setUp() { cm = new CoffeeMaker(); recipe1 = new Recipe(); recipe1.setName("Coffee"); recipe1.setPrice(50); recipe1.setAmtCoffee(6); recipe1.setAmtMilk(1); } public void testAddRecipe() { assertTrue(cm.addRecipe(recipe1)); }

JUnit and a Test Plan JUnit is good for: –Creating tests and keeping them with your code –Running them easily and seeing results quickly –Running them over and over. (Can run inside and outside Eclipse, e.g. in an automatic way.) But it’s a tool. You can plan and design your tests first so you use the tool well. The plan includes: –List of test cases –Each with a purpose/goal, what you expect to happen for a given input (5)

(6) Planning Your Tests How do we plan a “test case”? Plan: Define three parts first: –A purpose (why are we doing this particular test?) –An input –An expected result Execute: We run the test to see if observed output matched the expected result –It’s really just like a scientific experiment When testing, have a plan –At least in your head, but for serious testing, write it out ahead of time. –Don’t test blindly or randomly – you’ll waste your time

(7) Planning Your Tests These are poorly specified test cases! –Is any move OK? Be completely precise about situation, inputs, and expected outputs! Test IDDescriptionExpected Results Actual Results 1Player 1 rolls dice and moves. Player 1 moves on the board. 2Player 2 rolls dice and moves. Player 2 moves on the board.

(8) Planning Your Tests Why are these test cases better than the previous ones? Another good example later in the slides Test IDDescriptionExpected Results Actual Results 1Precondition: Game is in test mode, GameBoard is start configuration, and game begins. Number of Players: 2 Player 1 dice roll: 3 Player 1 moves to square Blue 3. 2Precondition: TestID 1 completed successfully. Player 2 dice roll: 3 Player 2 moves to square Blue 3.

How to Define Good Test Cases How do you come up with a good set of test cases? For each class –Test each method –Consider different situations of the “state” of the object and the parameters passed to the method Example: class BookShelf stored Book objects –Test method: boolean remove(int) in BookShelf –Should test: “Valid” removal calls: first item, last item, middle item Other calls: index too large or small What if BookShelf is empty? Make sure list actually changes! Make sure return value is correct! (9)

Types of Errors to Consider Details of these types of error or testing given in the following slides: –Boundary values –Off-by-one errors –Invalid inputs (10)

(11) Unit Testing: Boundary values Often programs misbehave because we make mistakes dealing with the “extremes” Examples: –The last item or first item in a collection –The start or end of a range of values Equivalent classes of test cases –Don’t have test cases or data that test the same situation (e.g. the middle of a range) Boundary or extreme conditions –An empty list, an empty file –One item in a list or file

(12) Unit Testing: Off-by-one errors Related to boundary conditions Using the nth value instead of n-1 Using 0 instead of 1 Executing a loop body once when it the body should not be executed at all Etc.

(13) Unit Testing: Invalid Inputs Rely on pre-conditions defined for your functions –They specify what the agreement is about what you are responsible for when its time to handle mis-use If a function is mis-used in this way –Return an error condition if the method provides a way to do this –Otherwise, halt program! Better than producing unexpected results Java has assertions that will test a condition and halt program. (These are not the same a JUnit assertions.)

(14) Example: Program with Student and Course classes Homework 0 this term –Define class Student methods include: –Define class Course methods include: Focus on defining: –Black-box test-cases for the method boolean drop(Course c) in class Student Let’s make a list of possible test-cases for this method!

(15) Example of Full Test-Case Description Test Case #1: Drop last course in list with >1 item –Purpose: Drop Course c for Student s where that course is the last course stored in the Student object's courses list. This tests the boundary condition of last item in list for Student.drop(c). –Input: Student s is enrolled in three courses, and the course to be dropped is the last of these stored in the list. –Expected output: The Student s is unchanged except that only two courses are stored for that student. Also, the list of students stored for that course is altered by having that student removed.

(16) Other Test Cases for this Program There are a lot! Boundary conditions? –for Student.drop(): end of list, start of list –same for Course.drop() –Question: is this affected by whether you used ArrayList instead of Java arrays? (yes) –Note: also test “typical” case, item in middle of list –Empty lists: Course.cancel(), Student.dropAll() Off-by-one errors? –Really included in boundary condition testing here

(17) Other Test Cases for this Program Invalid inputs? –See the specifications! –Test return values For boolean, test both success and failure Remember: make it fail! Test that your program handles that. Test of equals() methods? –If you get this wrong, trouble! –Easy to test. (Easy to forget to.)