5/9/2018 Advanced Unit Testing David Rabinowitz.

Slides:



Advertisements
Similar presentations
The Singleton Pattern II Recursive Linked Structures.
Advertisements

Chapter 1: Computer Systems
Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
Written by: Dr. JJ Shepherd
Lecture 27 Exceptions COMP1681 / SE15 Introduction to Programming.
The Java Programming Language
Outline Java program structure Basic program elements
Understanding class definitions – Part II –. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Coverage tools Program is typically compiled with special options, to add extra source or object code. –Additional data structures, such as a flow graph,
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt
Aditya V. Nori, Sriram K. Rajamani Microsoft Research India.
Cs2220: Engineering Software Class 6: Defensive Programming Fall 2010 University of Virginia David Evans.
COP-3330: Object Oriented Programming Flow Control May 16, 2012 Eng. Hector M Lugo-Cordero, MS.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Pre- and postconditions, Using assertions and exceptions 1 Pre- and postconditions Using assertions and exceptions.
Unit Testing CSIS 3701: Advanced Object Oriented Programming.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
© Spiros Mancoridis Software Engineering (Unit Testing Tools) Dependable Software Systems Topics in Unit Testing Tools Material drawn from [ junit.org,
Unit Testing Part 2: Drivers and Stubs
CSC 213 – Large Scale Programming. Today’s Goal  Understand why testing code is important  Result of poor or no testing & embarrassment caused  Learn.
© Dr. A. Williams, Fall Present Software Quality Assurance – Clover Lab 1 Tutorial / lab 2: Code instrumentation Goals of this session: 1.Create.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
CSE 143 Lecture 14: testing.
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Design Patterns – Chocolate Factory (from Head First Design Patterns)
Java Programming Language
Methods Attributes Method Modifiers ‘static’
Chapter 5: Control Structures II
White-Box Testing.
Software Engineering 1, CS 355 Unit Testing with JUnit
Java Programming: From Problem Analysis to Program Design, 4e
Engineering Innovation Center
Dependable Software Systems
Typescript Programming Languages
null, true, and false are also reserved.
Instructor: Alexander Stoytchev
Chapter 1: Computer Systems
Unit 3 - The while Loop - Extending the Vic class - Examples
CMSC 202 Exceptions 2nd Lecture.
CMSC 202 Exceptions 2nd Lecture.
Summary.
CSE 303 Concepts and Tools for Software Development
Instructor: Alexander Stoytchev
Recap Week 2 and 3.
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Copyright © – Curt Hill Bash Flow of Control Copyright © – Curt Hill.
Lecture Notes – Week 4 Chapter 5 (Loops).
Focus of the Course Object-Oriented Software Development
Whitebox Testing.
Automated test.
CMSC 202 Exceptions 2nd Lecture.
Instructor: Alexander Stoytchev
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Whitebox Testing.
CSE 1020:Software Development
Paul Ammann & Jeff Offutt
Exception Objects An exception is an abnormal condition that arises in a code sequence at rum time. Exception is a way of signaling serious problem.
Automated test.
HW#7 Describe test cases to reach full path coverage of the triangle program by completing the path condition table below. Also, draw the complete execution.
Software Testing.
Presentation transcript:

5/9/2018 Advanced Unit Testing David Rabinowitz

Object Oriented Design Course 5/9/2018 Test Coverage Tests are imperative for developing How to write tests How to know we have all important code covered? What are possible risks 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 What to test Correct results Cross checking Error conditions Boundaries Performance 5/9/2018 Object Oriented Design Course

Code coverage checking 5/9/2018 Code coverage checking How do we know that we have our critical code covered Statement coverage Branch coverage Path coverage How to make sure it will be done automatically 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Example public int foo(int x, boolean b1, boolean b2) { if (b1) { x++; } if (b2) { x = -x; return x; 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Tests Statement Coverage testTT() {int x=foo(0,true,true); ...} Branch Coverage testFF() {int x=foo(0,false,flase); ...} Path Coverage testTT(), testTF(), testFT(), testFF() 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Test coverage tools Monitor the tests Create a report of executed lines Examples Cobertura Clover many many more... 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 How they work Placing special markers in the code A post processor changes the generated bytecode The instrumented bytecode is put to a different directory The tests are run on the instrumented code 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Pitfalls Having high test coverage can lead to the (false) idea that our code is safe Tests may be covering 100% of the code, but not all the cases 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Example 1 public class PathCoverage { public String pathExample(boolean condition){ String value = null; if(condition){ value = " " + condition + " "; } return value.trim(); Taken from http://www-128.ibm.com/developerworks/java/library/j-cq01316/index.html 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Example 1 Test public class PathCoverageTest extends TestCase { public final void testPathExample() { PathCoverage pt = new PathCoverage(); String value = pt.pathExample(true); assertEquals("should be true", "true", value); } 5/9/2018 Object Oriented Design Course

Example 1 Coverage Report 5/9/2018 Example 1 Coverage Report 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Example 2 public class AnotherBranchCoverage { public void branchIt(int value){ if((value > 100) || (HiddenObject.doWork() == 0)){ this.dontDoIt(); }else{ this.doIt(); } private void dontDoIt(){ ... } private void doIt(){ ... } 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Example 2 public class HiddenObject { public static int doWork(){ //return 1; throw new RuntimeException("surprise!"); } 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Example 2 Test public class AnotherBranchCoverageTest extends TestCase { public final void testBranchIt() { AnotherBranchCoverage abc = new AnotherBranchCoverage(); abc.branchIt(101); } 5/9/2018 Object Oriented Design Course

Example 2 Coverage Report 5/9/2018 Example 2 Coverage Report 5/9/2018 Object Oriented Design Course

Object Oriented Design Course 5/9/2018 Summary Test coverage is a mean to check out the quality of our tests Line coverage Branch coverage Can be easily integrated to build scripts It cannot be taken for granted Results should be carefully examined 5/9/2018 Object Oriented Design Course