Software Test. Levels of test. Types of test. Regression test The JUnit tool for unit testing Java programs. System test Integration test Unit test

Similar documents
Object Oriented Software Design - I

Chapter 14 Software Testing Techniques

Test automation / JUnit. Building automatically repeatable test suites

Test automation Test automation / JUnit

Software Testing part II (white box) Lecturer: Giuseppe Santucci

Introduction to Software Engineering

Manuel Oriol, CHCRC-C, Software Testing ABB

No Source Code. EEC 521: Software Engineering. Specification-Based Testing. Advantages

Software Engineering Software Testing Techniques

linaye/gl.html

Test automation / JUnit. Building automatically repeatable test suites

Testing. CMSC 433 Programming Language Technologies and Paradigms Spring A Real Testing Example. Example (Black Box)?

Black Box Testing. EEC 521: Software Engineering. Specification-Based Testing. No Source Code. Software Testing

Test-Driven Development JUnit

Aerospace Software Engineering

SOFTWARE ENGINEERING IT 0301 Semester V B.Nithya,G.Lakshmi Priya Asst Professor SRM University, Kattankulathur

Chapter 9. Software Testing

Topics in Software Testing

Test-Driven Development JUnit

Software Engineering

EECS 4313 Software Engineering Testing

Tools for Unit Test - JUnit

Tuesday, November 15. Testing

Tools for Unit Test JUnit

Software Testing Fundamentals. Software Testing Techniques. Information Flow in Testing. Testing Objectives

Input Space Partitioning

Unit Testing with JUnit and CppUnit

Software Testing 2. OOD and Testability. White box vs Black box Testing. Software Testing 2 Semester 1, 2006

CS18000: Programming I

Darshan Institute of Engineering & Technology Unit : 9

Lecture 15 Software Testing

Chapter 14 Testing Tactics

Main concepts to be covered. Testing and Debugging. Code snippet of the day. Results. Testing Debugging Test automation Writing for maintainability

Software Engineering Testing and Debugging Testing

Verification and Validation. Assuring that a software system meets a user s needs. Verification vs Validation. The V & V Process

Software Testing and Maintenance

UNIT-4 Black Box & White Box Testing

MTAT : Software Testing

Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at

JUnit Framework. Terminology: assertions, annotations, fixtures. Dr. Siobhán Drohan Mairead Meagher. Produced by:

UNIT-4 Black Box & White Box Testing

XVIII. Software Testing. Laurea Triennale in Informatica Corso di Ingegneria del Software I A.A. 2006/2007 Andrea Polini

print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 3

TITAN 5300 Software. Unit Test Guidelines. S. Darling, S. Harpster, R. Hite, K. Konecki, W. Martersteck, R. Stewart. Revision 2.0

LECTURE 11 TEST DESIGN TECHNIQUES IV

Testing Stragegies. Black Box Testing. Test case

Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Agile Software Development. Lecture 7: Software Testing

F. Tip and M. Weintraub FUNCTIONAL TESTING

Introduction to Problem Solving and Programming in Python.

Computer Science and Software Engineering University of Wisconsin - Platteville 9-Software Testing, Verification and Validation

Software Engineering and Scientific Computing

Topics. Software Testing Test Driven Development Black Box Testing Unit Testing White Box Testing Coverage Testing Software Debugging

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Software Testing. Minsoo Ryu. Hanyang University. Real-Time Computing and Communications Lab., Hanyang University

CSE 403: Software Engineering, Fall courses.cs.washington.edu/courses/cse403/16au/ Unit Testing. Emina Torlak

Testing. Prof. Clarkson Fall Today s music: Wrecking Ball by Miley Cyrus

Chapter 11, Testing. Using UML, Patterns, and Java. Object-Oriented Software Engineering

Testing & Debugging TB-1

INTRODUCTION TO SOFTWARE ENGINEERING

(See related materials in textbook.) CSE 435: Software Engineering (slides adapted from Ghezzi et al & Stirewalt

Problem other classes messing with my stuff!

CS159. Nathan Sprague. September 30, 2015

QUIZ #5 - Solutions (5pts each)

Efficient Regression Test Model for Object Oriented Software

Verification and Validation. Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 22 Slide 1

MTAT : Software Testing

Introduc)on to tes)ng with JUnit. Workshop 3

Testing and Debugging

xtreme Programming (summary of Kent Beck s XP book) Stefan Resmerita, WS2015

CS 4387/5387 SOFTWARE V&V LECTURE 4 BLACK-BOX TESTING

Quality Assurance in Software Development

Software Testing. Massimo Felici IF

Analysis of the Test Driven Development by Example

Department of Electrical & Computer Engineering, University of Calgary. B.H. Far

CS 520 Theory and Practice of Software Engineering Fall 2018

Software Engineering I (02161)

Overview. State-of-the-Art. Relative cost of error correction. CS 619 Introduction to OO Design and Development. Testing.

Simple TDD Case Study. in Java

Automated testing in Agile SW development

Introduction to Software Testing Chapter 4 Input Space Partition Testing

MTAT : Software Testing

People tell me that testing is

Software Testing. Software Testing. in the textbook. Chapter 8. Verification and Validation. Verification and Validation: Goals

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy

Verification and Validation

1 Black Box Test Data Generation Techniques

Testing Process and Methods. CS 490MT/5555, Spring 2017, Yongjie Zheng

Darshan Institute of Engineering & Technology for Diploma Studies

Test-Driven Development (a.k.a. Design to Test) CSE260, Computer Science B: Honors Stony Brook University

Reliable programming

Using Code Coverage to Improve the Reliability of Embedded Software. Whitepaper V

Programming Embedded Systems

Introduction to JUnit. Data Structures and Algorithms for Language Processing

Practical Objects: Test Driven Software Development using JUnit

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy

Verification Overview Testing Theory and Principles Testing in Practice. Verification. Miaoqing Huang University of Arkansas 1 / 80

Chapter 10. Testing and Quality Assurance

Transcription:

Levels of test System test Integration test Unit test Types of test Black box White box Software Test Regression test The JUnit tool for unit testing Java programs OOP: Software Test 1

Introduction Sofware test is the process of executing a program with the intent of find errors [Glen Myers]. This should not be done by customers [K.Torp] Software test is an activity taking place after the program has been implemented and before the program is debugged. Implementation is an activity where design is converted to actual source code. Debugging is an activity where the causes of program malfunctions are found. Software testing is a very resource and time consuming activity A test can show that there is an error in a program. However, it can never show that a program is error free! OOP: Software Test 2

Unit, Integration, and System Tests A Need Finished System Requirements Failures System Test Success High-Level Design Failures Integration Test Success Low-level Design Failures Unit Test Success Code [source http://www.stsc.hill.af.mil/stscdocs] 3

Problems Related to Testing Test is done late in a project If it is done at all, it takes too long time to write test cases! I write code I do not test it Test cases gets outdated Test cases are for version 1.0 of the system which is currently now release in version 5.2. Test is incomplete Not all parts of the program are tested 4

Fewer bugs Advantages of Testing Less anoying product patching, more interesting development A better and more robust product Users are more likely to buy more software from your company Better sleep at nigth You know there are no obvious bugs in your program More proude of your company and its products See Darling, what I have build! Faster to release new versions of the product Buidling test cases is not a detour it is a short-cut! Test More, Spend Less! More aggresive changes of system Refactoring to build the best system possible 5

Disadvantages of Testing None! Absolutely none! Absolutely, definitively none! Absolutely, definitively, surely none! Absolutely, definitively, surely, conclusively none! Absolutely, definitively, surely, conclusively, decisively none! Absolutely, definitively, surely, conclusively, decisively, determantively none! Absolutely, definitively, surely, conclusively, decisively, determantively, positively none! Ran out of synonyms! 6

Testability Observability The results are easy to see Different outputs are generated for different inputs Incorrect outputs are easy to identify Controllability Processing can be controlled (e.g., wall clock) Running test cases can be automated (and easily repeated) Decomposability Modules can be tested individually Simplicity No huge and complex modules in the system Understandability The design of the system can be easily communicated from implementor to tester 7

Testability, cont. Testability must be taken into account during the design fase High testability cos(x) integer2string(int) return string insert(object) Low testability GUI, low controllability because hard to automate Recovery system of database management system Hard to thing of all possible error (low controllability, inputs hard to guess) The system is highly complex (low simplicity, low understandability) Extremly badly if it does not work correct 8

Single expression or statement Method Class Package Entire program Test Units 9

Black Box Test Look at the program from the outside, no knowledge of the internals Are requirement fulfilled Are interfaces available and working Can also reveal performance problems with the program Takes too long to compute Consumes too much main memory or disk space Can be applied to all levels of testing (unit, integration, system) Can be done by independent testers or even customers It is impossible to test for all possible inputs! 10

Look at an interval [A..B] Black Box Test, Examples Boundary value analysis Equivalence partitioning A B Look at a set S Equivalence partitioning Boundary value analysis (empty) Boundary value analysis (full) S S S 11

Black Box Test, cont. The challange in black box testing is picking the input values Equivalence partitioning (input domain partitioning) Partition input space into a small number of equivalent classes all elements in one class should be handled identically by the program Boundary value analysis A technique for identifying test cases to explore boundary conditions At boundaries there are typically many errors 12

Look inside the program White-Box Test Conditions and path taking with in the program Data flow Can be applied to unit tests Can be done by the developers or in house Black-box testing can be considered a subset of white-box testing for unit testing It is impossible to check all paths a program can take internally. 13

White-Box Test, cont. The challenge in white box testing is to exercise each line of code in the unit being tested at least once. A number of techniques exists for this Basis path coverage also called Cyclomatic Complexity Logical coverage Data flow coverage Basis path coverage is based on finding the basis set of paths for a programs path space. Defines the number of independent paths in the basis set Path coverage set is the set of paths that will execute all statements and all conditions in a program at least once Are not unique 14

White-Box Test, Example public static int mid(int a, int b, int c) { int res; if (a < b){ if (c < a) res = a; } else if (c < b) res = c; else res = b; } else{ // a >= b if (c < b) res = b; else if (c < a) res = c; else res = a; } return res; res=a c<a c<b a<b c<b res=c res=b res=b c<a res=c res=a 15

White-Box Test, Another Example // greatest common divisor public static int gcd(int u, int v){ int g = 1; while(u%2==0 && v%2==0){ // u is even and v is even u /= 2; // right shift v /=2; // right shift g *= 2; // (left shift) } // now u or v (or both) are odd int t; while (u > 0){ if (u%2==0){ u /= 2; } // u is even, u = u/2 else if (v%2==0){ v /= 2;} // v is even, v = v/2 else{ t = java.lang.math.abs(u-v)/2; //t = u-v /2 if (u < v) {v = t;} else {u = t;} } } return g*v; } 16

White-Box Test, Another Example, cont. g=1 false u%2==0 && v%s==0 true u/=2; v/=s; g*=2 loop int t false true u>0 true false u/=2 u>0 v>0 v/=2 true false t= u-v /2 loop v=t true u<v false u=t end loop return 17

Test Cases Describe how to test a unit (system/module/method/statement) Must include System state before execution of the test Part of system tested Input to the run test Expected outcome of the test (system state, output to screen, etc.) Good test cases will find bugs Good test cases are based on requirement specification 18

Regression Test Regression testing is a technique not a tool After a change to a piece of code two things must be tested That the changed piece of code works properly That the functionality of the entire system other than the change piece of code is unaffected It is very time consuming to test the two things above Automate Modularization of the system (with solid interfaces) The foundation for maintaining a good software product To avoid introducing error in the maintenance phase 19

JUnit and Unit Test For each unit ( program atoms ) write at least one test All unit tests can be executed at any time to ensure entire program is working properly For each change finished (before commit to CVS) all unit tests must succeed, i.e., no errors found Unit test central to the extreme programming paradigm Rapid feed back Assumed simplicity Incremental change Quality work 20

Assertion Unit Test Concepts The smallest building blocks of a unit test Expression that determines if a test succedes or fails Test case A collection of test methods e.g., the test for an entire class or method Test suite One or more test cases Entire test suite can be execute with a single command 21

Test Cases in JUnit, Example public class TestMiddleValue extends junit.framework.testcase{ // to have something to set up MiddleValue md; /** Sets up the test fixture */ protected void setup() { md = new MiddleValue(); } /** A test case */ public void testmidaequalbequalc(){ int val = md.mid(1,1,1); asserttrue(val==1); } } /** Another test case */ public void testmidasmallerthanb(){ int val; val = md.mid(50, 100, 10); asserttrue("did not return 50 but " + val, val==50); val = md.mid(50, 100, 70); asserttrue("did not return 70 but " + val, val==70); } 22

Assertions in JUnit asserttrue (boolean) assertfalse(boolean) assertequals(object, Object) assertnull(object) assertnotnull(object) // examples asserttrue(true); assertfalse(false); assertfalse("true is not false", true) assertnull(null); assertnotnull( hey ); 23

Test Cases in JUnit A test case in JUnit must inherit from the class junit.framework.testcase Methods of special importants setup() set up the test fixture Called before every test method teardown() tear down the test fixture Called after every test method test<method name>() a single test method The set of these method in a class is a test case 24

Test Suites in JUnit Collection of test cases in a single logical unit BlueJ will do this automatically for you! Test coverage No help from JUnit or BlueJ Add test until you run out of ideas for good things to test for Expensive products exists (not aware of any open source projects) Every time you write a System.out.println for test move it to a JUnit test case instead Reuse your work!!!! 25

Works very well with Function libraries API in general Having problem to deal with GUI Network Web Database Limits of JUnit Most test framework have these limitations 26

Advantages and Disadvantages of JUnit Advantages Small and very-well documented framework Can structure test better and make it much easier to run the tests Available for most Java development tools including BlueJ Testing becomes very systematic and partly automatic Defactor standard for unit testing Java programs Disadvantages No magic you have to write the test code your self Java specific but being ported to other languages JUnit is highly relevant for your projects!!! 27

Summary Testing is vital to provide a high-quality program. Up to 50% of time in real-world project may be testing. JUnit is a small Java based framework for unit testing Very handy and well-integrated with BlueJ, Eclipse, and other Java IDEs OOP: Software Test 28

Automate the Testing You have a combination of very strong tools at your disposition JUnit Cron jobs CVS Ant (build-tool like make) You can now Extract a specific version of your product Compile entire program and test Send an eail if there are errors in nightly tests Run test of experimental version of your program Generate documentation Combination used by several Aalborg companies. 29

White-Box Test, A Third Example // greatest common divisor public static boolean stringcompare(string x, String y){ boolean result = false; int m = x.length(); int n = y.length(); int i, j; } /* Searching */ for (j = 0; j <= n - m; ++j) { for (i = 0; i < m && x.charat(i) == y.charat(i + j); ++i); if (i >= m) result = true; } return result; 30

White-Box Test, a Third Example, cont. boolean result = false;... int i,j; j<=n-m true x.charat(i) = y.charat(i+j) false true false false i>=m true result= true loop end loop return 31

Interval Test Cases 32

Test Coverage Goal: To ensure that all statements and conditions have been executed at least once. Why: Studies show that logic errors and incorrect assumptions are inversely proportional to a path s execution probability. Typographical errors are distributed random across the program, it is therefore likely that untested paths will contain such errors. Often assumed by programmer that a particular path is not likely to be executed. However, reality is often counter intuitive. 33

Cyclomatic Complexity Industry studies have shown that the higher V(G), the higher the probability of errors. Defines the number of independent paths in the basis set Path coverage set is the set of paths that will execute all statements and all conditions in a program at least once Are not unique Define test cases for basis set 34