Overview. What is software testing? What is unit testing? Why/when to test? What makes a good test? What to test?

Similar documents
Test Driven Development

JUnit. Introduction to Unit Testing in Java

Test-Driven Development

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Logistics. Software Testing. Logistics. Logistics. Plan for this week. Before we begin. Project. Final exam. Questions?

The Interface Concept

Approach of Unit testing with the help of JUnit

Software Engineering. Top-Down Design. Bottom-Up Design. Software Process. Top-Down vs. Bottom-Up 13/02/2012

Test Driven Development

Efficient Data Structures for Decision Diagrams

Lecture Notes on Linear Search

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output:

Unit Testing & JUnit

Test Driven Development Part III: Continuous Integration Venkat Subramaniam

+ Introduction to JUnit. IT323 Software Engineering II By: Mashael Al-Duwais

C++ INTERVIEW QUESTIONS

Programming with Data Structures

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

CmpSci 187: Programming with Data Structures Spring 2015

Pseudo code Tutorial and Exercises Teacher s Version

Form Validation. Server-side Web Development and Programming. What to Validate. Error Prevention. Lecture 7: Input Validation and Error Handling

Common Data Structures

XP and TDD. Extreme Programming and Test Driven Development. Bertrand Meyer, Manuel Oriol Andreas Leitner. Chair of Software Engineering ETH Zurich

Java course - IAG0040. Unit testing & Agile Software Development

Chapter 4: Design Principles I: Correctness and Robustness

Introduction to Programming System Design. CSCI 455x (4 Units)

Code Obfuscation. Mayur Kamat Nishant Kumar

Tools for Integration Testing

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

Software Engineering Techniques

Stacks. Linear data structures

Zabin Visram Room CS115 CS126 Searching. Binary Search

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Java from a C perspective. Plan

RUP. Development Process. Iterative Process (spiral) Waterfall Development Process. Agile Development Process. Well-known development processes

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

>

CSE 308. Coding Conventions. Reference

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Introduction. Motivational Principles. An Introduction to extreme Programming. Jonathan I. Maletic, Ph.D.

In this Chapter you ll learn:

J a v a Quiz (Unit 3, Test 0 Practice)

Introduction to Computers and Programming. Testing

Regression Verification: Status Report

1. Use the class definition above to circle and identify the parts of code from the list given in parts a j.

Lecture J - Exceptions

CS 111 Classes I 1. Software Organization View to this point:

Introduction to Software Testing Chapter 8.1 Building Testing Tools Instrumentation. Chapter 8 Outline

Part I. Multiple Choice Questions (2 points each):

Course Intro Instructor Intro Java Intro, Continued

The resulting tile cannot merge with another tile again in the same move. When a 2048 tile is created, the player wins.

Analysis of a Search Algorithm

Unit 31 A Hypothesis Test about Correlation and Slope in a Simple Linear Regression

Testing, Debugging, and Verification

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

CS 451 Software Engineering Winter 2009

1 Description of The Simpletron

Chapter 2: Elements of Java

Introduction to Stacks

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Solving Problems Recursively

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

Hash Tables. Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Data Dictionary Revisited

Java Unit testing with JUnit 4.x in Eclipse

Abstraction and Abstract Data Types

Team Name : PRX Team Members : Liang Yu, Parvathy Unnikrishnan Nair, Reto Kleeb, Xinyi Wang

Agile Software Development. Venkat Subramaniam Agile Software Development

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Using Files as Input/Output in Java 5.0 Applications

1 Abstract Data Types Information Hiding

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Lecture Notes on Binary Search Trees

Token vs Line Based Processing

Two-Dimensional Arrays Summer 2010 Margaret Reid-Miller

Structured Testing in VDM

Evaluation of AgitarOne

Outline. 1 Denitions. 2 Principles. 4 Implementation and Evaluation. 5 Debugging. 6 References

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

13 File Output and Input

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1

Chapter 15 Functional Programming Languages

1.3 Conditionals and Loops

Fail early, fail often, succeed sooner!

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

PHP Arrays for RPG Programmers

1 White-Box Testing by Stubs and Drivers

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Test case design techniques I: Whitebox testing CISS

Software Testing. Jeffrey Carver University of Alabama. April 7, 2016

Transcription:

Testing CMSC 202

Overview What is software testing? What is unit testing? Why/when to test? What makes a good test? What to test? 2

What is Software Testing? Software testing is any activity aimed at evaluating an attribute or capability of a program or system and determining that it meets its required results. William Hetzel The Complete Guide to Software Testing 3

Types of Software Testing Unit Testing Verifies the functionality of a specific chunk of code, usually at the function/class level Integration Testing Testing of combined modules as a whole System Testing Tests fully integrated system against requirements System Integration Testing Testing between multiple systems 4

Unit Testing A unit test is a piece of code written by a developer that exercises a very small, specific area of functionality in the code being tested. Usually a unit test exercises some particular method in a particular context. Andy Hunt & Dave Thomas Pragmatic Unit Testing 5

Unit Testing Also known as component testing In OOP, typically ensures that a method/class works as designed Written by developers to test their code. Also known as white box testing 6

Why Test? You wouldn t do this without a safety net. Why develop your code without one? 7

When to Test How many of you write almost all of your code and then write some tests To fulfill project requirements? To exercise and test your code? How many of you incrementally write tests to exercise code as your write it? Anyone write the tests first? 8

Pay Now or Pay Later It s cheaper in the long run to pay as you go. Minimizes trying to solve many problems at once at the end of your development cycle 9

Test Driven Development Test Driven Development (TDD) takes this pay early approach a step further by requiring that you write the tests before writing non-test code. 1. Add tests 2. Run tests, new tests should fail 3. Write code to satisfy tests 4. Re-run tests; all tests should pass 5. Refactor as needed 6. Repeat 10

Properties of Good Unit Tests What are things we aim for in good tests? Repeatable Should be able to be re-run producing the same results (avoid randomness, getting current time, etc.) Independent Only test one feature (method) at a time. Tests should not be dependent upon one another. Provide value Testing simple getters/setters is probably not a good use of time. Thorough Test all class invariants, pre/post conditions, edge cases. 11

Thoroughness In order for your tests to be thorough, you need to check for several things. General Correctness Boundary Conditions Error Conditions 12

General Correctness These are the so-called easy tests to write. These test the general cases. 13

Boundary Conditions Ordering Does various ordering affect the outcome? Range zero, minimum, maximum, positive #s, negative #s Existence Null values for reference parameters Empty things Collections (e.g. arrays) Strings Cardinality Expected number of items 14

Error Conditions Are the right exceptions getting raised under the right conditions? I/O issues Missing files Unreadable files Empty files 15

Exercise Identify test cases for the following method. public static int largest(int[ ] list) { /* code */ } What tests might we have for each of the following areas? General correctness Boundary conditions Error conditions 16

A Buggy Implementation How many of your tests failed on the following buggy implementation of largest? public static int largest(int[ ] list) { int max = Integer.MAX_VALUE; for(int i = 0; i < list.length - 1; i++) { if(list[i] > max) { max = list[i]; } } return max; } 17

A Much Improved largest Method public static int largest(int[] list) { if(list == null) { throw new IllegalArgumentException("list cannot be null"); } else if (list.length == 0) { throw new IllegalArgumentException("list cannot be empty"); } } int max = Integer.MIN_VALUE; for(int i = 0; i < list.length; i++) { if(list[i] > max) { max = list[i]; } } return max; 18

Additional Resources Pragmatic Unit Testing in Java with JUnit Free Introduction chapter Free testing Summary cheat-sheet JUnit Test Infected: Programmers Love Writing Tests 19