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.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Ch. 2 Exploring core JUnit. This chapter covers ■ Using the core JUnit classes ■ Understanding JUnit mechanisms ■ Understanding the JUnit lifecycle.
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
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
SE 450 Software Processes & Product Metrics Reliability: An Introduction.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
JUnit, Revisited 17-Apr-17.
JUnit Introduction and Advanced Features. Topics Covered  Junit Introduction  Fixtures  Test Suites  Currency Example.
JUnit. Why is testing good? Due to psychological factors, programmers are bad testers. A computer can test much faster than a human Philosophy: “If it.
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.
14-Jul-15 JUnit 4. Comparing JUnit 3 to JUnit 4 All the old assertXXX methods are the same Most things are about equally easy JUnit 4 makes it easier.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
© 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.
Class Library, Formatting, Wrapper Classes, and JUnit Testing
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Stacks. An alternative storage structure for collections of entities is a stack. A stack is a simplified form of a linked list in which all insertions.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
Test automation / JUnit Building automatically repeatable test suites.
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.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
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
By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development (TDD)
JUnit Automated Software Testing Framework Advanced Material Paul Ammann & Jeff Offutt
JUnit. Introduction JUnit is an open source Java testing framework used to write and run repeatable tests JUnit is integrated with several IDEs, including.
JUnit SWE 619 Summer July 18, 2007 SWE 619 (c) Aynur Abdurazik 2 What is JUnit? Open source Java testing framework used to write and run repeatable.
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved.
2-1 By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Testing: Fundamentals of Making a Good Test Presented by Emerson Murphy-Hill Based on Slides by ©Paul Ammann and Jeff Offutt
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Lecture 5: Test-Driven Development Basics
Paul Ammann & Jeff Offutt
TESTING TEST DRIVEN DEVELOPMENT
Introduction to Classes and Objects
JUnit Automated Software Testing Framework
Test Automation CS 4501 / 6501 Software Testing
Introduction to JUnit CS 4501 / 6501 Software Testing
More JUnit CS 4501 / 6501 Software Testing
Object-Orientated Programming
An Automated Testing Framework
Java Review: Reference Types
Software Engineering 1, CS 355 Unit Testing with JUnit
JUnit Automated Software Testing Framework
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 3 Test Automation
Test-driven development (TDD)
Introduction to JUnit CS 4501 / 6501 Software Testing
Test Automation CS 4501 / 6501 Software Testing
CS 1111 Introduction to Programming Fall 2018
Defining Classes and Methods
Java Statements B.Ramamurthy CS114A, CS504 4/23/2019 BR.
Operator Overloading; String and Array Objects
JUnit Reading: various web pages
Classes, Objects and Methods
JUnit SWE 619 Spring 2008.
Paul Ammann & Jeff Offutt
CMSC 202 Exceptions.
Presentation transcript:

More JUnit CS 4501 / 6501 Software Testing [Ammann and Offutt, “Introduction to 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 2) Execute program under test 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 or ArrayOperationsNumZeroTest 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 Objects should be initialized in a @Before method Objects 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 Run each set of data values with the same tests Implement data-driven testing with JUnit Parameterized mechanism @Parameters annotation defines collection of data values

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

Wrap-up Automate as much as possible to make testing efficient as well as effective Test frameworks provide very simply ways to automate our 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) Test automation is not “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 What’s Next? Test-Driven Development