Softwaretechnik. Testing and Debugging Testing II. Matthias Keil. Albert-Ludwigs-Universität Freiburg

Similar documents
Testing, Debugging, and Verification

Unit-testing with JML

Approach of Unit testing with the help of JUnit

Unit Testing. and. JUnit

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

Author: Sascha Wolski Sebastian Hennebrueder Tutorials for Struts, EJB, xdoclet and eclipse.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

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

TESTING WITH JUNIT. Lab 3 : Testing

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

Announcement. SOFT1902 Software Development Tools. Today s Lecture. Version Control. Multiple iterations. What is Version Control

Software Engineering Techniques

Unit Testing & JUnit

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Efficient Data Structures for Decision Diagrams

CPSC 330 Software Engineering

Experimental Comparison of Concolic and Random Testing for Java Card Applets

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Slides prepared by : Farzana Rahman TESTING WITH JUNIT IN ECLIPSE

JUnit. Introduction to Unit Testing in Java

JUnit Automated Software Testing Framework. Jeff Offutt. SWE 437 George Mason University Thanks in part to Aynur Abdurazik. What is JUnit?

Computing Concepts with Java Essentials

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

Part 3: GridWorld Classes and Interfaces

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

Fail early, fail often, succeed sooner!

Tool-Assisted Unit-Test Generation and Selection Based on Operational Abstractions

AP Computer Science Java Mr. Clausen Program 9A, 9B

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

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

Test Case Design Techniques

Evaluation of AgitarOne

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

LINKED DATA STRUCTURES

Java Interview Questions and Answers

Unit Testing JUnit and Clover

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

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

Writing Self-testing Java Classes with SelfTest

Capabilities of a Java Test Execution Framework by Erick Griffin

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

Programming with Data Structures

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Lecture Notes on Linear Search

Unit Testing and JUnit

How to Write AllSeen Alliance Self- Certification Test Cases September 25, 2014

Comparing the Effectiveness of Penetration Testing and Static Code Analysis

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

Agile/Automated Testing

CSE 326: Data Structures. Java Generics & JUnit. Section notes, 4/10/08 slides by Hal Perkins

Table of Contents. LESSON: The JUnit Test Tool...1. Subjects...2. Testing What JUnit Provides...4. JUnit Concepts...5

Effective unit testing with JUnit

Computer Programming I

Object Oriented Software Design

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

Introduction to Computers and Programming. Testing

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:

Tools for Integration Testing

Java Application Developer Certificate Program Competencies

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

Software Construction

Systematic software testing

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Introduction to Triggers using SQL

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

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

Object Oriented Software Design

Sources: On the Web: Slides will be available on:

Test case design techniques I: Whitebox testing CISS

Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1

Know or Go Practical Quest for Reliable Software

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

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

PA2: Word Cloud (100 Points)

1 White-Box Testing by Stubs and Drivers

Test case design techniques I: Whitebox testing CISS

Java Unit testing with JUnit 4.x in Eclipse

Ordered Lists and Binary Trees

Introduction to Java

Unit Testing with junit. based on materials by M. Stepp, M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia

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

Regression Verification: Status Report

1 Description of The Simpletron

Unit testing with EUnit. Richard Carlsson

Pemrograman Dasar. Basic Elements Of Java

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

Data Structures and Algorithms Lists

Software Engineering for LabVIEW Applications. Elijah Kerry LabVIEW Product Manager

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 1 October 14, Instructions

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

Using JUnit in SAP NetWeaver Developer Studio

National University of Ireland, Maynooth MAYNOOTH, CO. KILDARE, IRELAND. Testing Guidelines for Student Projects

Mail User Agent Project

Unit Testing with Monkeys Karl-Mikael Björklid University of Jyväskylä Department of Mathematical Information Technology

4. Test Design Techniques

How To Write A Test Engine For A Microsoft Microsoft Web Browser (Php) For A Web Browser For A Non-Procedural Reason)

Lab Experience 17. Programming Language Translation

JUnit - A Whole Lot of Testing Going On

Monday, April 8, 13. Creating Successful Magento ERP Integrations

Algorithms and Data Structures Written Exam Proposed SOLUTION

Transcription:

Softwaretechnik Testing and Debugging Testing II Matthias Keil Institute for Computer Science Faculty of Engineering University of Freiburg 14. Juni 2012

Introduction Summary Specifications (motivation, contracts, pre- and postconditions, what to think about) Testing (motivation, different kinds of testing, role in software development, junit) Matthias Keil Softwaretechnik 14. Juni 2012 2 / 30

Introduction Summary Specifications (motivation, contracts, pre- and postconditions, what to think about) Testing (motivation, different kinds of testing, role in software development, junit) What s next? More examples of test cases, presenting aspects of writing test cases and features of JUnit How to write a good test case? How to construct a good collection of test cases (test suite)? Matthias Keil Softwaretechnik 14. Juni 2012 2 / 30

Basic JUnit Usage Let s review the basic example of using junit. public class Ex1 { public static int find_ min ( int [] a) { int x, i; x = a [0]; for (i = 1; i < a. length ;i ++) { if (a[i] < x) x = a[i]; } return x; }... Matthias Keil Softwaretechnik 14. Juni 2012 3 / 30

Basic JUnit Usage continued from prev page... public static int [] insert ( int [] x, int n) { int [] y = new int [x. length + 1]; int i; for (i = 0; i < x. length ; i ++) { if (n < x[i]) break ; y[i] = x[i]; } y[i] = n; for (; i < x. length ; i ++) { y[i +1] = x[i]; } return y; } } Matthias Keil Softwaretechnik 14. Juni 2012 4 / 30

@ Test public void test_ insert_ 1 () { int [] x = {2, 7}; int n = 6; int [] res = Ex1. insert (x, n); int [] expected = {2, 6, 7}; asserttrue ( Array. equals ( expected, res )); } } Matthias Keil Softwaretechnik 14. Juni 2012 5 / 30 Basic JUnit Usage import org. junit.*; import static org. junit. Assert.*; import java. util.*; public class Ex1Test { @ Test public void test_ find_ min_ 1 () { int [] a = {5, 1, 7}; int res = Ex1. find_min (a); asserttrue ( res == 1); }

Using the IUT to Setup or Check the Test May need to call methods in the class under test to set up a test case, to decide the outcome (testing oracle) How do we know that those methods do what they are supposed to, so that the method which is actually under test isn t incorrectly blamed for a failure? Matthias Keil Softwaretechnik 14. Juni 2012 6 / 30

Using the IUT to Setup or Check the Test May need to call methods in the class under test to set up a test case, to decide the outcome (testing oracle) How do we know that those methods do what they are supposed to, so that the method which is actually under test isn t incorrectly blamed for a failure? The helper methods of a test should be tested themselves in other test cases. There should be some ordering such that at most one new method is tested for each new test case. Sometimes there can be circular dependencies which do not permit this approach. In that case it is up to the tester to decide in what method call the cause of the failure lies. Matthias Keil Softwaretechnik 14. Juni 2012 6 / 30

public void add (X x) { for ( int i = 0; i < arr. size (); i ++) { if (x. equals ( arr. get (i))) return ; } arr. add (x); }... Matthias Keil Softwaretechnik 14. Juni 2012 7 / 30 Example Using IUT to setup and decide test case, and use fixture and common tests. import java. util.*; public class Ex2_Set <X > { private ArrayList <X > arr ; public Ex2_ Set () { arr = new ArrayList <X >() ; }

public void union ( Ex2_Set <X > s) { for ( int i = 0; i < s. arr. size (); i ++) { add (s. arr. get (i)); } } Matthias Keil Softwaretechnik 14. Juni 2012 8 / 30 Example contd continued from prev page... public boolean member ( X x) { for ( int i = 0; i < arr. size (); i ++) { if (x. equals ( arr. get (i))) return true ; } return false ; } public int size () { return arr. size (); }

Example contd import org. junit.*; import static org. junit. Assert.*; import java. util.*; public class Ex2_ SetTest { private Ex2_Set < String > s, s2; @ Before public void setup () { s = new Ex2_Set < String >() ; s. add (" one "); s. add (" two "); s2 = new Ex2_Set < String >() ; s2.add (" two "); s2.add (" three "); }... Matthias Keil Softwaretechnik 14. Juni 2012 9 / 30

Example contd... private void testset ( String [] exp, Ex2_Set < String > s) { asserttrue (s. size () == exp. length ); for ( int i = 0; i < s. size (); i ++) { asserttrue (s. member ( exp [i])); } } } @ Test public void test_ union_ 1 () { s. union (s2); String [] exp = {" one ", " two ", " three "} testset (exp, s); } Matthias Keil Softwaretechnik 14. Juni 2012 10 / 30

Performing More Than one Test in the Same Method With JUnit it s in principle possible to perform more than one test in a test case method, because failures are reported as exceptions (which includes line numbers where they occurred) Matthias Keil Softwaretechnik 14. Juni 2012 11 / 30

Performing More Than one Test in the Same Method With JUnit it s in principle possible to perform more than one test in a test case method, because failures are reported as exceptions (which includes line numbers where they occurred) We just talked about a situation where this may be necessary. Matthias Keil Softwaretechnik 14. Juni 2012 11 / 30

Performing More Than one Test in the Same Method With JUnit it s in principle possible to perform more than one test in a test case method, because failures are reported as exceptions (which includes line numbers where they occurred) We just talked about a situation where this may be necessary. But in other situations it may also seem appealing to put several tests in one methods. Matthias Keil Softwaretechnik 14. Juni 2012 11 / 30

Performing More Than one Test in the Same Method With JUnit it s in principle possible to perform more than one test in a test case method, because failures are reported as exceptions (which includes line numbers where they occurred) We just talked about a situation where this may be necessary. But in other situations it may also seem appealing to put several tests in one methods. Best practise: keep them apart in individual methods and use fixtures and such to keep the code compact. Matthias Keil Softwaretechnik 14. Juni 2012 11 / 30

Preamble Fixture Often several tests need to set up in the same or a similar way. Matthias Keil Softwaretechnik 14. Juni 2012 12 / 30

Preamble Fixture Often several tests need to set up in the same or a similar way. This common setup of a set of tests is called preamble, or fixture. Matthias Keil Softwaretechnik 14. Juni 2012 12 / 30

Preamble Fixture Often several tests need to set up in the same or a similar way. This common setup of a set of tests is called preamble, or fixture. Write submethods which perform the common setup, and which are called from each test case. Matthias Keil Softwaretechnik 14. Juni 2012 12 / 30

Preamble Fixture Often several tests need to set up in the same or a similar way. This common setup of a set of tests is called preamble, or fixture. Write submethods which perform the common setup, and which are called from each test case. A slightly more convenient (but less flexible) way is to use the JUnit @Before and @After annotations. Matthias Keil Softwaretechnik 14. Juni 2012 12 / 30

Preamble Fixture Often several tests need to set up in the same or a similar way. This common setup of a set of tests is called preamble, or fixture. Write submethods which perform the common setup, and which are called from each test case. A slightly more convenient (but less flexible) way is to use the JUnit @Before and @After annotations. See previous example Matthias Keil Softwaretechnik 14. Juni 2012 12 / 30

Testcases are Programs Often similar kinds of tests are used in many test cases to decide if the succeeded or failed. Matthias Keil Softwaretechnik 14. Juni 2012 13 / 30

Testcases are Programs Often similar kinds of tests are used in many test cases to decide if the succeeded or failed. Write methods which are called by many test cases. Matthias Keil Softwaretechnik 14. Juni 2012 13 / 30

Testcases are Programs Often similar kinds of tests are used in many test cases to decide if the succeeded or failed. Write methods which are called by many test cases. As JUnit tests are implemented in Java, all Java features may be used to make writing test cases more convenient Matthias Keil Softwaretechnik 14. Juni 2012 13 / 30

Testcases are Programs Often similar kinds of tests are used in many test cases to decide if the succeeded or failed. Write methods which are called by many test cases. As JUnit tests are implemented in Java, all Java features may be used to make writing test cases more convenient See previous example Matthias Keil Softwaretechnik 14. Juni 2012 13 / 30

Abnormal Termination JUnit propagates the result of an assertion by throwing an exception Matthias Keil Softwaretechnik 14. Juni 2012 14 / 30

Abnormal Termination JUnit propagates the result of an assertion by throwing an exception Default treatment: report failureif the IUT throws an exception Matthias Keil Softwaretechnik 14. Juni 2012 14 / 30

Abnormal Termination JUnit propagates the result of an assertion by throwing an exception Default treatment: report failureif the IUT throws an exception Most of the time: correct behavior (no unhandled exceptions in the IUT) Matthias Keil Softwaretechnik 14. Juni 2012 14 / 30

Abnormal Termination JUnit propagates the result of an assertion by throwing an exception Default treatment: report failureif the IUT throws an exception Most of the time: correct behavior (no unhandled exceptions in the IUT) To override this behaviour, there are two options: Matthias Keil Softwaretechnik 14. Juni 2012 14 / 30

Abnormal Termination JUnit propagates the result of an assertion by throwing an exception Default treatment: report failureif the IUT throws an exception Most of the time: correct behavior (no unhandled exceptions in the IUT) To override this behaviour, there are two options: Catch and analyse exceptions thrown by IUT in the test case method, or Matthias Keil Softwaretechnik 14. Juni 2012 14 / 30

Abnormal Termination JUnit propagates the result of an assertion by throwing an exception Default treatment: report failureif the IUT throws an exception Most of the time: correct behavior (no unhandled exceptions in the IUT) To override this behaviour, there are two options: Catch and analyse exceptions thrown by IUT in the test case method, or Give an expected optional element of the @Test annotation Matthias Keil Softwaretechnik 14. Juni 2012 14 / 30

Exceptions Example Exception means failure: @ Test public void test_ find_ min_ 1 () { int [] a = {}; int res = Ex1. find_min (a); } Matthias Keil Softwaretechnik 14. Juni 2012 15 / 30

Exceptions Example Exception means failure: @ Test public void test_ find_ min_ 1 () { int [] a = {}; int res = Ex1. find_min (a); } Exception means success: @ Test ( expected = Exception. class ) public void test_find_min_1 () { int [] a = {}; int res = Ex1. find_min (a); } Matthias Keil Softwaretechnik 14. Juni 2012 15 / 30

Non-termination Another general property that the IUT should have is that when calling a method with fulfilled precondition, then execution of the method should terminate. Matthias Keil Softwaretechnik 14. Juni 2012 16 / 30

Non-termination Another general property that the IUT should have is that when calling a method with fulfilled precondition, then execution of the method should terminate. Non-termination becomes obvious when running a test suite, because it hangs on a particular test. Matthias Keil Softwaretechnik 14. Juni 2012 16 / 30

Non-termination Another general property that the IUT should have is that when calling a method with fulfilled precondition, then execution of the method should terminate. Non-termination becomes obvious when running a test suite, because it hangs on a particular test. Better way: use the timeout option of @Test Matthias Keil Softwaretechnik 14. Juni 2012 16 / 30

Non-termination Another general property that the IUT should have is that when calling a method with fulfilled precondition, then execution of the method should terminate. Non-termination becomes obvious when running a test suite, because it hangs on a particular test. Better way: use the timeout option of @Test If termination (or running time) is an issue for a certain part of the IUT, specify a timeout for the relevant test cases. Matthias Keil Softwaretechnik 14. Juni 2012 16 / 30

Non-termination Another general property that the IUT should have is that when calling a method with fulfilled precondition, then execution of the method should terminate. Non-termination becomes obvious when running a test suite, because it hangs on a particular test. Better way: use the timeout option of @Test If termination (or running time) is an issue for a certain part of the IUT, specify a timeout for the relevant test cases. If the execution of the tests does not terminate after this time, JUnit reports a failure, and the test runner proceeds with the remaining tests. Matthias Keil Softwaretechnik 14. Juni 2012 16 / 30

What is a Correct Test Case? Correct test case Obvious: the outcome check at the end of the test should signal success if the IUT did what it should, and failure if it didn t Easier to forget: the setup before the call and the parameters sent along should correspond to the intended usage of the IUT. Matthias Keil Softwaretechnik 14. Juni 2012 17 / 30

What is a Correct Test Case? Correct test case Obvious: the outcome check at the end of the test should signal success if the IUT did what it should, and failure if it didn t Easier to forget: the setup before the call and the parameters sent along should correspond to the intended usage of the IUT. In both cases we use the specification The setup of the test should fulfill the specified precondition of the tested method, the outcome check should adhere to the postcondition Matthias Keil Softwaretechnik 14. Juni 2012 17 / 30

public static void f( Integer a, Integer b, Integer c) {... } Specification Requires: a b and b c Ensures:... Matthias Keil Softwaretechnik 14. Juni 2012 18 / 30

public static void f( Integer a, Integer b, Integer c) {... } Specification Requires: a b and b c Ensures:... Testing f(): f(2, 5, 6) =... valid Matthias Keil Softwaretechnik 14. Juni 2012 18 / 30

public static void f( Integer a, Integer b, Integer c) {... } Specification Requires: a b and b c Ensures:... Testing f(): f(2, 5, 6) =... valid f(1, 4, 4) =... valid Matthias Keil Softwaretechnik 14. Juni 2012 18 / 30

public static void f( Integer a, Integer b, Integer c) {... } Specification Requires: a b and b c Ensures:... Testing f(): f(2, 5, 6) =... valid f(1, 4, 4) =... valid f(3, 7, 5) =... not valid Matthias Keil Softwaretechnik 14. Juni 2012 18 / 30

How to Write a Good Test Suite? Apart from getting each test case right, we also want the tests in a test suite to test an IUT in as many different ways as possible. Matthias Keil Softwaretechnik 14. Juni 2012 19 / 30

How to Write a Good Test Suite? Apart from getting each test case right, we also want the tests in a test suite to test an IUT in as many different ways as possible. Maximize the chance that a bug is found by running the test suite. Matthias Keil Softwaretechnik 14. Juni 2012 19 / 30

How to Write a Good Test Suite? Apart from getting each test case right, we also want the tests in a test suite to test an IUT in as many different ways as possible. Maximize the chance that a bug is found by running the test suite. Common approach: find a set of tests which has a good coverage. Matthias Keil Softwaretechnik 14. Juni 2012 19 / 30

Black-box and White-box Testing The activity of deriving test cases can be divided into two categories wrt what sources of information are used. Matthias Keil Softwaretechnik 14. Juni 2012 20 / 30

Black-box and White-box Testing The activity of deriving test cases can be divided into two categories wrt what sources of information are used. Black-box testing The tester has access to a specification and the compiled code only. The specification is used to derive test cases and the code is executed to see if it behaves correctly. Matthias Keil Softwaretechnik 14. Juni 2012 20 / 30

Black-box and White-box Testing The activity of deriving test cases can be divided into two categories wrt what sources of information are used. Black-box testing The tester has access to a specification and the compiled code only. The specification is used to derive test cases and the code is executed to see if it behaves correctly. White-box testing The tester has also access to the source code of the IUT. The code can be used in addition to the specification to derive test cases. Matthias Keil Softwaretechnik 14. Juni 2012 20 / 30

Black-box Testing The basic idea is to analyse the specification and try to cover all cases that it discriminates. In addition, the tests should include cornes cases of the involved types. Matthias Keil Softwaretechnik 14. Juni 2012 21 / 30

Either... Or The two alternatives represent two different situations. public static Y f(x[] x) {... } Specification Requires: x is either null or is non-null and contains at least one element. Ensures:... Matthias Keil Softwaretechnik 14. Juni 2012 22 / 30

Either... Or The two alternatives represent two different situations. public static Y f(x[] x) {... } Specification Requires: x is either null or is non-null and contains at least one element. Ensures:... Testing f(): f(null) =... Matthias Keil Softwaretechnik 14. Juni 2012 22 / 30

Either... Or The two alternatives represent two different situations. public static Y f(x[] x) {... } Specification Requires: x is either null or is non-null and contains at least one element. Ensures:... Testing f(): f(null) =... f({x, y}) =... Matthias Keil Softwaretechnik 14. Juni 2012 22 / 30

If... Then... Otherwise The two alternatives represent two different situations. public static int half ( int n) {... } Specification Requires: Ensures: Returns int, m, such that: If n is even n = 2 m, otherwise n = 2 m + 1 Matthias Keil Softwaretechnik 14. Juni 2012 23 / 30

If... Then... Otherwise The two alternatives represent two different situations. public static int half ( int n) {... } Specification Requires: Ensures: Testing half(): Returns int, m, such that: If n is even n = 2 m, otherwise n = 2 m + 1 half(4) = 2 Matthias Keil Softwaretechnik 14. Juni 2012 23 / 30

If... Then... Otherwise The two alternatives represent two different situations. public static int half ( int n) {... } Specification Requires: Ensures: Testing half(): Returns int, m, such that: If n is even n = 2 m, otherwise n = 2 m + 1 half(4) = 2 half(7) = 3 Matthias Keil Softwaretechnik 14. Juni 2012 23 / 30

Inequalities The cases <, = and > represent different situations. public static int min ( int a, int b) {... } Specification Requires: Ensures: If a < b then returns a, otherwise returns b Matthias Keil Softwaretechnik 14. Juni 2012 24 / 30

Inequalities The cases <, = and > represent different situations. public static int min ( int a, int b) {... } Specification Requires: Ensures: Testing min(): If a < b then returns a, otherwise returns b min(2, 5) = 2 Matthias Keil Softwaretechnik 14. Juni 2012 24 / 30

Inequalities The cases <, = and > represent different situations. public static int min ( int a, int b) {... } Specification Requires: Ensures: Testing min(): If a < b then returns a, otherwise returns b min(2, 5) = 2 min(3, 3) = 3 Matthias Keil Softwaretechnik 14. Juni 2012 24 / 30

Inequalities The cases <, = and > represent different situations. public static int min ( int a, int b) {... } Specification Requires: Ensures: Testing min(): If a < b then returns a, otherwise returns b min(2, 5) = 2 min(3, 3) = 3 min(7, 1) = 1 Matthias Keil Softwaretechnik 14. Juni 2012 24 / 30

Other sources of distinctions Objects non-null or null Arrays empty or non-empty Integers zero, positive or negative Booleans true or false Matthias Keil Softwaretechnik 14. Juni 2012 25 / 30

White-box Testing A white-box tester has more information at hand and may write a better test suite. Matthias Keil Softwaretechnik 14. Juni 2012 26 / 30

White-box Testing A white-box tester has more information at hand and may write a better test suite. Not only the intended behavior but also the particular implementation can be reflected in the test cases. Matthias Keil Softwaretechnik 14. Juni 2012 26 / 30

White-box Testing A white-box tester has more information at hand and may write a better test suite. Not only the intended behavior but also the particular implementation can be reflected in the test cases. The specification is still needed to check if each individual test case is correct. (Correct use of IUT and test oracle) Matthias Keil Softwaretechnik 14. Juni 2012 26 / 30

White-box Testing A white-box tester has more information at hand and may write a better test suite. Not only the intended behavior but also the particular implementation can be reflected in the test cases. The specification is still needed to check if each individual test case is correct. (Correct use of IUT and test oracle) The normal way of making use of the source code is to write test cases which cover the code as good as possible code coverage Matthias Keil Softwaretechnik 14. Juni 2012 26 / 30

White-box Testing A white-box tester has more information at hand and may write a better test suite. Not only the intended behavior but also the particular implementation can be reflected in the test cases. The specification is still needed to check if each individual test case is correct. (Correct use of IUT and test oracle) The normal way of making use of the source code is to write test cases which cover the code as good as possible code coverage The idea is that, by exercising all parts of a program, a bug should not be able to escape detection. Matthias Keil Softwaretechnik 14. Juni 2012 26 / 30

White-box Testing A white-box tester has more information at hand and may write a better test suite. Not only the intended behavior but also the particular implementation can be reflected in the test cases. The specification is still needed to check if each individual test case is correct. (Correct use of IUT and test oracle) The normal way of making use of the source code is to write test cases which cover the code as good as possible code coverage The idea is that, by exercising all parts of a program, a bug should not be able to escape detection. Advantage: Code coverage is a quantitative measure of how thouroughly an implementation has been tested. Matthias Keil Softwaretechnik 14. Juni 2012 26 / 30

White-box Testing A white-box tester has more information at hand and may write a better test suite. Not only the intended behavior but also the particular implementation can be reflected in the test cases. The specification is still needed to check if each individual test case is correct. (Correct use of IUT and test oracle) The normal way of making use of the source code is to write test cases which cover the code as good as possible code coverage The idea is that, by exercising all parts of a program, a bug should not be able to escape detection. Advantage: Code coverage is a quantitative measure of how thouroughly an implementation has been tested. However, there are no field studies that support it... Matthias Keil Softwaretechnik 14. Juni 2012 26 / 30

Code Coverage Code coverage can be defined in several ways. The most frequently seen types of code coverage are Statement (or line) coverage: Every statement in the code should be executed at least once by the test suite. Branch coverage: Every branching point in the program should be executed, and for each of them all alternatives should be executed. Path coverage: All possible execution paths should be represented among the test cases. (Full path coverage is not possible in general.) Matthias Keil Softwaretechnik 14. Juni 2012 27 / 30

public static int [] merge ( int [] x, int [] y) { int [] z = new int [x. length + y. length ]; int i, j; for (i = 0, j = 0; i < x. length && j < y. length ;) { if (x[i] < y[j]) { z[i + j] = x[i]; i ++; } else { z[i + j] = y[j]; j ++; } } for (; i < x. length ; i ++) { z[i + j] = x[i]; } for (; j < x. length ; j ++) { z[i + j] = y[j]; } return z; } Matthias Keil Softwaretechnik 14. Juni 2012 28 / 30

Path Coverage Not possible to test all paths Infinitely many in general instead of all, test up to a given maximum number of iterations of loops Matthias Keil Softwaretechnik 14. Juni 2012 29 / 30

Path Coverage Not possible to test all paths Infinitely many in general instead of all, test up to a given maximum number of iterations of loops Not all paths are possible Due to the logical relationship between branching points not all paths may be possible keep in mind when deriving test cases Matthias Keil Softwaretechnik 14. Juni 2012 29 / 30

Summary (Testing) Informal software specifications Introduction to software testing (motivation, terminology) Writing test cases, in general and using JUnit Deriving test cases Black-box testing White-box testing and Code coverage Matthias Keil Softwaretechnik 14. Juni 2012 30 / 30