JUnit A Cook's Tour. Kent Beck and Erich Gamma. Renaat Verbruggen 1#

Similar documents
JUnit: The Goals of JUnit

2. Reasons for implementing clos-unit

Topics in Object-Oriented Design Patterns

Unit Testing with JUnit and CppUnit

JUnit in EDA Introduction. 2 JUnit 4.3

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Practical Objects: Test Driven Software Development using JUnit

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

The Strategy Pattern Design Principle: Design Principle: Design Principle:

15-498: Distributed Systems Project #1: Design and Implementation of a RMI Facility for Java

Software Design and Analysis CSCI 2040

JUnit Test Patterns in Rational XDE

Object-Oriented Concepts and Design Principles

Junit Overview. By Ana I. Duncan

Inheritance and Polymorphism in Java

Promoting Component Architectures in a Dysfunctional Organization

Lecture 17: Case Study: JUnit

Analysis of the Test Driven Development by Example

Design Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns

Design Patterns IV Structural Design Patterns, 1

SDC Design patterns GoF

4. A Testing Framework

McCa!"s Triangle of Quality

1: Introduction to Object (1)

Object-Oriented Design

A SCHEME UNIT-TESTING FRAMEWORK

Understanding Design Pattern Density with Aspects

Object Oriented Software Design - I

Reengineering II. Transforming the System

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Fractions and their Equivalent Forms

Software testing A.A. 2018/2019

LECTURE 3 ADMINISTRATION SECTION -A

Introduction. A Brief Description of Our Journey

University of Berne Institute of Computer Science

CS251 Software Engineering Lectures 18: Intro to DP

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

Object-Oriented Oriented Programming

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

CSSE 220 Day 3. Check out UnitTesting and WordGames from SVN

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

Capturing JUnit Behavior into Static Programs

Software Engineering I (02161)

PATTERNS AND SOFTWARE DESIGN

Introduction to Extreme Programming. Extreme Programming is... Benefits. References: William Wake, Capital One Steve Metsker, Capital One Kent Beck

The Power of Unit Testing and it s impact on your business. Ashish Kumar Vice President, Engineering

Using Design Patterns in Java Application Development

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

JUnit 4 and Java EE 5 Better Testing by Design

Design Patterns Reid Holmes

Test-Driven Development (TDD)

What is Testing? Table of Contents

Design Patterns V Structural Design Patterns, 2

COMP 354 TDD and Refactoring

Tackling Design Patterns Chapter 3: Template Method design pattern and Public Inheritance. 3.1 Introduction... 2

Patterns Of Enterprise Application Architecture

Testing and Debugging

As a programmer, you know how easy it can be to get lost in the details

Using Inheriting and Overloading concept in creating reusable universal test method library

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

Design Patterns Design patterns advantages:

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Software Engineering - I An Introduction to Software Construction Techniques for Industrial Strength Software

Evolving Software. CMSC 433 Programming Language Technologies and Paradigms Spring Example. Some Motivations for This Refactoring

Trombone players produce different pitches partly by varying the length of a tube.

Module 10 Inheritance, Virtual Functions, and Polymorphism

Creating a new form with check boxes, drop-down list boxes, and text box fill-ins. Customizing each of the three form fields.

Unit E Step-by-Step: Programming with Python

4. A Testing Framework. Oscar Nierstrasz

Inheritance and Polymorphism

Design patterns. Jef De Smedt Beta VZW

Object-Oriented Design

The SD-WAN security guide

Object Oriented Paradigm

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors

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

Pair projects due Thursday I do not anticipate giving any extensions for this assignment. 3/2/ Larry Snyder, CSE 1

Test First Software Development

Refactorings. Refactoring. Refactoring Strategy. Demonstration: Refactoring and Reverse Engineering. Conclusion

Static Methods. Why use methods?

Test-Driven Development

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Recitation 13. Software Engineering Practices and Introduction to Design Patterns

Principles of Computer Game Design and Implementation. Lecture 3

Convention over Configuration

Software Design and Analysis for Engineers

Design Stories Exploring and Creating Code from a Narrative Perspective Kevlin

Designing and Writing a Program. Divide and Conquer! The Design-Code-Debug Cycle. Documentation is Code. Pair Programming 3/8/2012

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

DESIGN PATTERN - INTERVIEW QUESTIONS

Principles of Object-Oriented Design

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Programming II (CS300)

COURSE 2 DESIGN PATTERNS

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Transcription:

JUnit A Cook's Tour Kent Beck and Erich Gamma Renaat Verbruggen 1#

JUnit advice "Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead." Martin Fowler At first create a new fixtures all the time Soon, reusing your library of fixtures and new tests as simple as adding a method to an existing TestCase subclass. Renaat Verbruggen 2#

You can always write more tests! However, you will quickly find that only a fraction of the tests you can imagine are actually useful. What you want is to write tests that fail even though you think they should work, or tests that succeed even though you think they should fail. Another way to think of it is in cost/benefit terms. You want to write tests that will pay you back with information. Renaat Verbruggen 3#

A reasonable return on your testing investment: During Development- When you need to add new functionality to the system, write the tests first. Then, you will be done developing when the test runs. During Debugging- When someone discovers a defect in your code, first write a test that will succeed if the code is working. Then debug until the test succeeds. Renaat Verbruggen 4#

One word of caution about your tests. Once you get them running, make sure they stay running. There is a huge difference between having your suite running and having it broken. Ideally, you would run every test in your suite every time you change a method. Practically, your suite will soon grow too large to run all the time. Try to optimize your setup code so you can run all the tests. Or, at the very least, create special suites that contain all the tests that might possibly be affected by your current development. Then, run the suite every time you compile. And make sure you run every test at least once a day: overnight, during lunch, during one of those long meetings. Renaat Verbruggen 5#

JUnit Cook s Tour The Patterns 6

Getting started- TestCase If we want to make manipulating tests easy, we have to make them objects. The Command pattern fits our needs quite nicely. Quoting from the intent, "Encapsulate a request as an object, thereby letting you queue or log requests " Command tells us to create an object for an operation and give it a method "execute". Renaat Verbruggen 7#

Notation run a TestCase Renaat Verbruggen 8#

Blanks to fill in- run() The next problem to solve is giving the developer a convenient "place" to put their fixture code and their test code. Template Method addresses our problem quite nicely. Quoting from the intent, "Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm s structure." Renaat Verbruggen 9#

TestCase.run() applies Template Method Renaat Verbruggen 10#

Reporting results- TestResult It is called Collecting Parameter. It suggests that when you need to collect results over several methods, you should add a parameter to the method and pass an object that will collect the results for you. We create a new object, TestResult, to collect the results of running tests. Renaat Verbruggen 11#

TestResult applies Collecting Parameter Renaat Verbruggen 12#

No stupid subclasses - TestCase again Reviewing the problems addressed by available design patterns, the Adapter pattern springs to mind. Adapter has the following intent "Convert the interface of a class into another interface clients expect". The simplest form of pluggable behavior is the Pluggable Selector. The Java reflection API allows us to invoke a method from a string representing the method s name Renaat Verbruggen 13#

Renaat Verbruggen 14#

Don t care about one or many - TestSuite Composite. To quote its intent "Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly." Renaat Verbruggen 15#

Renaat Verbruggen 16#

Summary Notice how TestCase, the central abstraction in the framework, is involved in four patterns. Pictures of mature object designs show this same "pattern density". The star of the design has a rich set of relationships with the supporting players. Renaat Verbruggen 17#

Renaat Verbruggen 18#

Storyboard Here is another way of looking at all of the patterns in JUnit. In this storyboard you see an abstract representation of the effect of each of the patterns in turn. So, the Command pattern creates the TestCase class, the Template Method pattern creates the run method, and so on. One point to notice about the storyboard is how the complexity of the picture jumps when we apply Composite. This is pictorial corroboration for our intuition that Composite is a powerful pattern, but that it "complicates the picture." It should therefore be used with caution. Renaat Verbruggen 19#

JUnit Pattern Storyboard Renaat Verbruggen 20#

Conclusion Patterns We found discussing the design in terms of patterns to be invaluable, both as we were developing the framework and as we try to explain it to others. Pattern density There is a high pattern "density" around TestCase, which is the key abstraction of JUnit. Designs with high pattern density are easier to use but harder to change. Renaat Verbruggen 21#

Eat your own dog food As soon as we had the base unit testing functionality implemented, we applied it ourselves. Intersection, not union There is a temptation in framework development to include every feature you can. However, the fewer features the framework has, the easier it is to learn, the more likely a developer will use it. JUnit is written in this style. It implements only those features absolutely essential to running tests- running suites of tests, isolating the execution of tests from each other, and running tests automatically. Renaat Verbruggen 22#

Framework writers read their code We spent far more time reading the JUnit code than we spent writing it, and nearly as much time removing duplicate functionality as we spent adding new functionality. We experimented aggressively with the design, adding new classes and moving responsibility around in as many different ways as we could imagine. We were rewarded (and are still being rewarded) for our monomania by a continuous flow of insights into JUnit, testing, object design, framework development, and opportunities for further articles. Renaat Verbruggen 23#