Mock Objects. What are Mock Objects  Any dummy object that stands in for a real object that is not available, or is difficult to use in a test case 

Slides:



Advertisements
Similar presentations
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Basic OO Technology Technology determines the effectiveness of the approach.
Advertisements

Written by: Dr. JJ Shepherd
Sequence Diagram Generation & Validation MSE First Presentation Samer Saleh Advisor: Bill Hankley.
Exceptions and Exception Handling Carl Alphonce CSE116 March 9, 2007.
Exceptions and Exception Handling Carl Alphonce CSE116.
Integration Testing When testing a module in isolation –Called modules need to be replaced –Tested module needs to be called A D ′ E ′ main driver module.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Exceptions and Exception Handling (1) Carl Alphonce CSE116.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Reuse Activities Selecting Design Patterns and Components
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Programmer Testing Testing all things Java using JUnit and extensions.
Pair Programming Testing 2, October 14, Administration  Project due Monday 2PM SHARP  Remember all parts of documentation (list of tests, project.
Introduction to the Enterprise Library. Sounds familiar? Writing a component to encapsulate data access Building a component that allows you to log errors.
Smith’s Aerospace © P. Bailey & K. Vander Linden, 2005 Architecture: Component and Deployment Diagrams Patrick Bailey Keith Vander Linden Calvin College.
Design Patterns.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
Capture-Replay Mocks Scandinavian Developer Conference 4 th April 2011 Geoff Bache.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
.NET Framework Danish Sami UG Lead.NetFoundry
Programming Models & Runtime Systems Breakout Report MICS PI Meeting, June 27, 2002.
Tot 15 LTPDA Graphic User Interface summary and status N. Tateo 26/06/2007.
Junit At the forefront of Test Driven Development.
CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.
Next-generation databases Active databases: when a particular event occurs and given conditions are satisfied then some actions are executed. An active.
Test Isolation and Mocking Technion – Institute of Technology Author: Gal Lalouche © 1 Author: Gal Lalouche - Technion 2015 ©
Replay Compilation: Improving Debuggability of a Just-in Time Complier Presenter: Jun Tao.
1 Kuali Nervous System (KNS) Part 2 Presented by: Jerry Neal – KFS Development Manager Geoff McGregor – KC Lead Developer Brian McGough – KRice Project.
Java Portals and Portlets Submitted By: Rashi Chopra CIS 764 Fall 2007 Rashi Chopra.
Using Mock Objects with Test Driven Development Justin Kohlhepp
TEST-1 6. Testing & Refactoring. TEST-2 How we create classes? We think about what a class must do We focus on its implementation We write fields We write.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
Mock objects.
1 MotoHawk Components Scalable, Secure, Model-Based Design of Embedded Systems MotoHawk Training.
Software testing techniques Software testing techniques Object-oriented software testing Presentation on the seminar Kaunas University of Technology.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Testing Spring Applications Unit Testing.
(1) Test Driven Development Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Mock Me If You Can An Introduction to the Mocking Framework Mockito Symposium on Software Performance 2014 Christian Wulf ― Software Engineering.
Declarative Languages and Model Based Development of Web Applications Besnik Selimi South East European University DAAD: 15 th Workshop “Software Engineering.
Presented by Syed Baber Development Lead Mazik Global.
Mocking with Moq Tools for Easier Unit Testing SoftUni Team Technical Trainers Software University
Exceptions Lecture 11 COMP 401, Fall /25/2014.
Mocking with Moq Mocking tools for easier unit testing Svetlin Nakov Technical Trainer Software University
Unified Modeling Language (UML)
Lecture IX: Testing Web Services with Mocking CS 4593 Cloud-Oriented Big Data and Software Engineering.
Google C++ Testing Framework Part 2: Assertion. Concepts A test case contains one or many tests. ◦ You should group your tests into test cases that reflect.
PYTHON FOR HIGH PERFORMANCE COMPUTING. OUTLINE  Compiling for performance  Native ways for performance  Generator  Examples.
Test Isolation and Mocking Technion – Institute of Technology Author: Gal Lalouche © 1 Author: Gal Lalouche - Technion 2016 ©
Testing PA165 Dec 9, 2014 Petr Adámek, Tomáš Pitner.
Software Development – Topic 2 Types of Programming Language.
COTS testing Torbjørn Skramstad.
PHPUnit vs PHPSpec © Rudolf Horváth
Mocking tools for easier unit testing
Test Isolation and Mocking
Object-oriented software testing
Designing For Testability
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Quick guide to moq Presenter: PhuongNQK.
COTS testing Tor Stålhane.
History, Characteristics and Frameworks
Mocking Your Objects with Impunity
Object-Oriented Programming
Software Architecture
Testing a persistence layer
Developing and testing enterprise Java applications
Designing For Testability
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Test-Driven Development
Presentation transcript:

Mock Objects

What are Mock Objects  Any dummy object that stands in for a real object that is not available, or is difficult to use in a test case  (More rigid): A mock object must have the ability to set up expectations and provide a self-validation mechanism

Why use Mock Objects?  Help keep design decoupled  Check code’s usage of another object  Test code from the inside out  Make tests run faster  Make it easier to write code for problematic resources  Defer having to write a class  Test components in isolation from the rest of the system  Promote interface-based design  Encourage composition over inheritance  Refine interfaces  Test unusual, unlikely, and exceptional situations

When to use Mock Objects  Non-deterministic or random behavior  Difficult setup  Behavior hard to cause  Slow real objects  UIs  Test needs to make queries not supported by real object  Non-existent real objects

How to use Mock Objects  Create them by hand from scratch  Create them by hand, using the MockObjects library  Use MockMaker to generate the mock object prior to execution  Use EasyMock to generate the mock object at runtime

By hand from scratch  Create a class that implements the same interface as the real one  Hard code return values  Lots of work to create and validate expectations

By hand with MockObjects library  Create the mocks  Set state/expectations  Execute code  Have mocks verify expectations  Lots of duplication across Mocks

MockMaker  Given an interface or class, create a mock object for it  Mock can then be tweaked

EasyMock  Create mock object at runtime  Two modes: record and replay

EasyMock adjustments  Make the following adjustments to EasyMock example code in the book:  EasyMock.niceControlFor should be MockControl.createControl  control.activate should be control.replay

EasyMock Matcher  Easymock by default uses Object.equals() type comparison  For arrays, this doesn’t look at content  Solution: the first time you call a method that takes an array as a parameter, set the matcher before setting return value