JUnit Automated Software Testing Framework Advanced Material Paul Ammann & Jeff Offutt

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Advertisements

Introduction to Software Testing Chapter 1
Introduction to Software Testing (2nd edition) Chapter 3 Test Automation Paul Ammann & Jeff Offutt aretest/ Second.
Introduction to Software Testing Chapter 3.3 Logic Coverage for Source Code Paul Ammann & Jeff Offutt
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
Introduction to Software Testing Chapter 3.3 Logic Coverage from Source Code Paul Ammann & Jeff Offutt.
Introduction to Software Testing Chapter 1 Paul Ammann & Jeff Offutt SUMMARY OF PARTS 1 AND 2 FROM LAST WEEK.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
Introduction to Software Testing Chapter 2.3 Graph Coverage for Source Code Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved. Slides Prepared.
Introduction to Software Testing Chapter 2.5 Graph Coverage for Specifications Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt
Code Contracts Parameterized Unit Tests Tao Xie. Example Unit Test Case = ? Outputs Expected Outputs Program + Test inputs Test Oracles 2 void addTest()
332 Final Review Last updated Fall 2013 Professor Ammann.
Introduction to Software Testing Chapter 2.3 Graph Coverage for Source Code Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Software Testing and Quality Assurance Practical Considerations (4) 1.
Introduction to Software Testing (2nd edition) Chapter 7.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
JUnit. Introduction JUnit is an open source Java testing framework used to write and run repeatable tests JUnit is integrated with several IDEs, including.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
13 Aug 2013 Program Verification. Proofs about Programs Why make you study logic? Why make you do proofs? Because we want to prove properties of programs.
Class Design I Class Contracts Readings: 2 nd Ed: Section 9.5, Advanced Topic nd Ed: Section 8.5, Advanced Topic 8.2 Some ideas come from: “Practical.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved.
Introduction to Software Testing (2nd edition) Chapter 3 Test Automation Paul Ammann & Jeff Offutt Updated.
CSE 143 Lecture 4 More ArrayIntList : Pre/postconditions; exceptions; testing reading: slides created by Marty Stepp and Hélène Martin
CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Unit Testing. F-22 Raptor Fighter Manufactured by Lockheed Martin & Boeing How many parts does the F-22 have?
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
Software Testing and Maintenance Lecture 3 Graph Coverage for Source Code Paul Ammann & Jeff Offutt Instructor: Hossein Momeni Mazandaran.
619 Final Review Last updated Fall 2011 Paul Ammann.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Introduction to Software Testing (2nd edition) Chapter 5 Criteria-Based Test Design Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Unit Testing with JUnit
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
CS427: Software Engineering I
JUnit Automated Software Testing Framework
Introduction to JUnit CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
More JUnit CS 4501 / 6501 Software Testing
Intro To Classes Review
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
JUnit Automated Software Testing Framework
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 3 Test Automation
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to Software Testing (2nd edition) Chapter 4 TDD Example
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
More JUnit CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
CSE 1020:Software Development
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Presentation transcript:

JUnit Automated Software Testing Framework Advanced Material Paul Ammann & Jeff Offutt

Introduction to Software Testing (Ch 1) © Ammann & Offutt 2 Advanced Topics in JUnit Assertion Patterns –How To Decide If Your Test Passes –State Testing vs. Interaction Testing Patterns Parameterized JUnit Tests –How to Describe and Run Very Similar Tests JUnit Theories –Applying the Contract Model to Testing –AAA Model: Assume, Act, Assert –Very Powerful Approach But Also Still A Work in Progress

Introduction to Software Testing (Ch 1) © Ammann & Offutt 3 Assertion Patterns for Unit Tests State Testing Patterns –Final State Assertion Most Common Pattern: Arrange. Act. Assert. –Guard Assertion Assert Both Before and After The Action (Precondition Testing) –Delta Assertion Verify a Relative Change to the State –Custom Assertion Encodes Complex Verification Rules Interaction Assertions –Verify Expected Interactions –Heavily used in Mocking tools –Very Different Analysis Compared to State Testing Resource:

Introduction to Software Testing (Ch 1) © Ammann & Offutt 4 Parameterized JUnit Tests Problem: Testing A Function With Similar Values –How To Avoid Test Code Bloat? Simple Example: Adding Two Numbers –Adding a Given Pair of Numbers Is Just Like Adding Any Other Pair –You Really Only Want to Write One Test Parameterized Unit Tests Call Consructor For Each Logical Set of Data Values –Same Tests Are Then Run On Each Set of Data Values –List of Data Values Identified Annotation

Introduction to Software Testing (Ch 1) © Ammann & Offutt 5 Parameterized Unit Tests import org.junit.*; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import static org.junit.Assert.*; import public class ParamTest { public int sum, a, b; public ParamTest (int sum, int a, int b) { this.sum = sum; this.a = a; this.b = b; public static Collection parameters() { return Arrays.asList (new Object [][] {{0, 0, 0}, {2, 1, 1}}); public void additionTest() { assertEquals(sum, a+b); } }

Introduction to Software Testing (Ch 1) © Ammann & Offutt 6 JUnit Theories These Are Unit Tests With Actual Parameters –So Far, We’ve Only Seen Parameterless Test Methods Contract Model: Assume, Act, Assert –Assumptions (Preconditions) Limit Values Appropriately –Action Performs Activity Under Scrutiny –Assertions (Postconditions) Check public void removeThenAddDoesNotChangeSet( Set set, String string) { // Parameters! assumeTrue(set.contains(string)) ; // Assume Set copy = new HashSet (set); // Act copy.remove(string); copy.add(string); assertTrue (set.equals(copy)); // Assert // // System.out.println(“Instantiated test: “ + set + “, “ + string); }

Introduction to Software Testing (Ch 1) © Ammann & Offutt 7 Question: Where Does The Data Come From? Answer: –All Combinations of Values Annotations Where Assume Clause is True –Four (of Nine) Combinations in This Particular Case Format is an public static String[] string = {"ant", "bat", public static Set[] sets = { new HashSet(Arrays.asList("ant", "bat")), new HashSet(Arrays.asList(“bat", “cat", “dog“, “elk”)), new HashSet(Arrays.asList(“Snap”, “Crackle”, “Pop")) };

Introduction to Software Testing (Ch 1) © Ammann & Offutt 8 JUnit Theories Need BoilerPlate import org.junit.*; import org.junit.runner.RunWith; import static org.junit.Assert.*; import static org.junit.Assume.*; import org.junit.experimental.theories.DataPoint; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import public class SetTheoryTest { … // See Earlier Slides }