More JUnit CS 4501 / 6501 Software Testing

Slides:



Advertisements
Similar presentations
J-Unit Framework.
Advertisements

MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
The Fundamental Rule for Testing Methods Every method should be tested in a program in which every other method in the testing program has already been.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Approach of Unit testing with the help of JUnit Satish Mishra
JUnit, Revisited 17-Apr-17.
JUnit Introduction and Advanced Features. Topics Covered  Junit Introduction  Fixtures  Test Suites  Currency Example.
24-Jun-15 JUnit. 2 Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (running whatever tests.
TDD Test-Driven Development. JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to.
Writing a Unit test Using JUnit At the top of the file include: import junit.framework.TestCase; The main class of the file must be: public Must extend.
Ranga Rodrigo. Class is central to object oriented programming.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Unit and Functional Testing Your Flex Applications Mike Nimer Dir. Of Engineering nomee.com.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
CSC 395 – Software Engineering Lecture 10: Execution-based Testing –or– We can make it better than it was. Better...faster...agiler.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
Today’s Agenda  Reminder: HW #1 Due next class  Quick Review  Input Space Partitioning Software Testing and Maintenance 1.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
A tool for test-driven development
Object Oriented Programing (OOP)
JUnit Automated Software Testing Framework Advanced Material Paul Ammann & Jeff Offutt
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
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.
CSE 143 Lecture 4 More ArrayIntList : Pre/postconditions; exceptions; testing reading: slides created by Marty Stepp and Hélène Martin
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Chapter 7 Programming by contract: preconditions and postconditions.
Object-Oriented Programming “The Rest of the Story”, CS 4450 – Chapter 16.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.
Winter 2006CISC121 - Prof. McLeod1 Stuff Midterm exam in JEF234 on March 9th from 7- 9pm.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Lecture 5: Test-Driven Development Basics
Abstract Data Type.
EECE 310: Software Engineering
TESTING TEST DRIVEN DEVELOPMENT
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
JUnit Automated Software Testing Framework
Test Automation CS 4501 / 6501 Software Testing
Introduction to JUnit CS 4501 / 6501 Software Testing
Input Space Partition Testing CS 4501 / 6501 Software Testing
CSE 374 Programming Concepts & Tools
Section 11.1 Class Variables and Methods
An Automated Testing Framework
Software Engineering 1, CS 355 Unit Testing with JUnit
Stack Data Structure, Reverse Polish Notation, Homework 7
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
Introduction to Software Testing Chapter 3 Test Automation
Test-driven development (TDD)
CSE 1030: Implementing Non-Static Features
Introduction to JUnit CS 4501 / 6501 Software Testing
Test Automation CS 4501 / 6501 Software Testing
CS 1111 Introduction to Programming Fall 2018
More JUnit CS 4501 / 6501 Software Testing
Defining Classes and Methods
Go to pollev.com/cse143.
Java Statements B.Ramamurthy CS114A, CS504 4/23/2019 BR.
JUnit Reading: various web pages
Classes, Objects and Methods
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
TCSS 360, Spring 2005 Lecture Notes
JUnit SWE 619 Spring 2008.
slides created by Ethan Apter and Marty Stepp
Presentation transcript:

More JUnit CS 4501 / 6501 Software Testing

Common methods assertTrue(boolean condition) review assertTrue(boolean condition) Assert that a condition is true assertTrue(String message, boolean condition) If the assertion is true, the string is ignored. If the assertion is not true, the string is sent to the test engineer. assertEquals(Object expected, Object actual) Assert that two objects are equal fail(String message) If a certain situation is expected when a certain section of code is reached, the string is sent to the test engineer. Often used to test exceptional behavior

JUnit – Test Classes Imports Test class Test method Another test review Imports Test class Test method Another test method

JUnit – Test Methods 1) Setup test case values review 1) Setup test case values 2) Execute program under test 3) Assert expected vs. actual test outputs 4) Printed if assert fails expected actual output

JUnit / xUnit - Conventions Group related test methods in a single test class The name of test packages/classes/methods should at least transmit: The name of the subject under test (SUT) class TestArrayOperationsNumZero The name of the method or feature being tested The purpose of the test case testNumZeroEmptyArray It is common to prefix or suffix test classes with “Test” and prefix test methods with “test”

Exceptions as Expected Results Equivalent This pattern is more verbose and unnecessary in this case. It is useful in situations when we wish to perform other assertions beyond the expected exception behavior

JUnit Test Fixtures A test fixture is the state of the test Objects and variables that are used by more than one test Initializations (prefix values) Reset values (postfix values) Different tests can use the objects without sharing the state Objects used in test fixtures should be declared as instance variables They should be initialized in a @Before method Can be deallocated or reset in an @After method

Prefix / Postfix Actions Initialize objects and variables that are used by more than one test Reset objects and variables that are used by more than one test

Data-Driven Tests Sometimes, the same test method needs to be run multiple times, with the only difference being the input values and the expected output Data-driven unit tests call a constructor for each collection of test values Same tests are then run each set of data values JUnit Parameterized mechanism implements data-driven testing Collection of data values defined by method tagged with @Parameters annotation

Example: JUnit Data-Driven Unit Test Necessary import Returns a collection with 2 arrays of inputs and expected outputs (thus, call the constructor twice) Data-driven test Constructor is called for each triple of values Test 1 Test values: 1, 1 Expected: 2 Test 2 Test values: 2, 3 Expected: 5 Test method uses the instance variables initialized in the constructor call

JUnit Theories Unit tests can have actual parameters So far, we have only seen parameterless test methods Contract model: Assume, Act, Assert Assumptions (preconditions) limit values appropriately Action performs activity under scrutiny Assertions (postconditions) check result Predondition: the starting set contains the necessary string Otherwise, the theory will fail

JUnit Theories Unit tests can have actual parameters So far, we have only seen parameterless test methods Contract model: Assume, Act, Assert Assumptions (preconditions) limit values appropriately Action performs activity under scrutiny Assertions (postconditions) check result Action: remove a string from a list and then adds the string back in

JUnit Theories Unit tests can have actual parameters So far, we have only seen parameterless test methods Contract model: Assume, Act, Assert Assumptions (preconditions) limit values appropriately Action performs activity under scrutiny Assertions (postconditions) check result This theory is only true if the starting set already contains the string being removed Assert: check the result

Where Do The Data Values Come From? All combinations of values from @DataPpoints annotations where assume clause is true @DataPoints format is an array 3 values 3 values 9 possible combinations of values 4 combinations satisfy the precondition and also satisfy the postcondition If a precondition is not satisfied, the postcondition does not apply

Summary The only way to make testing efficient as well as effective is to automated as much as possible Test frameworks provide very simply ways to automate out test Data-driven testing can suffer from a combinatorial explosion in the number of tests (cross-product of the possible values for each of the parameters in the unit tests) It is no “silver bullet” however .. It does not solve the hard problem of testing “What test values to use?” This is test design .. The purpose of test criteria