Mock Me If You Can An Introduction to the Mocking Framework Mockito Symposium on Software Performance 2014 Christian Wulf ― 26.11.2014 Software Engineering.

Slides:



Advertisements
Similar presentations
PhUSE 2010 Unit Testing and Code Coverage Assessment with SASUnit - Key Technologies for Development of reliable SAS Macros - HMS Analytical Software.
Advertisements

The map and reduce functions in MapReduce are easy to test in isolation, which is a consequence of their functional style. For known inputs, they produce.
Implementation of an Android Phone Based Video Streamer 2010 IEEE/ACM International Conference on Green Computing and Communications 2010 IEEE/ACM International.
Software Construction
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.
ITEC200 Week02 Program Correctness and Efficiency.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
Well-behaved objects 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
The Waterfall Model A Case Study
16/27/2015 3:38 AM6/27/2015 3:38 AM6/27/2015 3:38 AMTesting and Debugging Testing The process of verifying the software performs to the specifications.
And now … Graphs simulation input file parameters 10,000 requests 4 categories of file sizes 1K- 80% frequency 4K – 15% 16K – 4% 64K –1% poisson arrival.
Mockito Introduction What is Mockito? – Mockito is mocking frame work for Java Objects.
Unit Testing Using PyUnit Monther Suboh Yazan Hamam Saddam Al-Mahasneh Miran Ahmad
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 
Programmer Testing Testing all things Java using JUnit and extensions.
Toward a Generic and Concurrency-Aware Pipes & Filters Framework Symposium on Software Performance 2014 Christian Wulf, Nils Christian Ehmke, and Wilhelm.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
1 CSE 2102 CSE 2102 CSE 2102: Introduction to Software Engineering Ch9: Software Engineering Tools and Environments.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Capture-Replay Mocks Scandinavian Developer Conference 4 th April 2011 Geoff Bache.
Magnetic Field Measurement System as Part of a Software Family Jerzy M. Nogiec Joe DiMarco Fermilab.
Automated GUI testing How to test an interactive application automatically?
Factory Method A Creational Design Pattern. Factory Method Key Features  Defines an interface for creating objects without needing to know each object’s.
Sayed Ahmed Computer Engineering, BUET, Bangladesh Masters from the University of Manitoba, Canada
Software testing Main issues: There are a great many testing techniques Often, only the final code is tested.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
Manifold Lab 2 Introduction Basic Concepts First Examples.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Software Engineering Design Patterns. Singleton Single instance of class Constructor is private static final Class instance constructed when application.
Singleton and Basic UML CS340100, NTHU Yoshi. What is UML Unified Modeling Language A standardized general-purpose modeling language in the field of software.
Chapter 5: Ball Worlds Features 2 classes, constant data fields, constructors, extension through inheritance, graphics.
Jaguar/JaguarPF Optimized Library Interface (JOLI) Yashema Mack Florida Agricultural & Mechanical University Dr. Rebecca Hartman-Baker National Center.
Celluloid An interactive media sequencing language.
Unit Testing Beyond Mock Objects Sven Rosvall ACCU 2014.
Employing Wikis for online collaboration in the e-learning environment: Case study 1 Raitman, R., Augar, N. & Zhou, W. (2005). Employing Wikis for online.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
International Summer School in Parallel Patterns 2014 Software Engineering Group by Prof. Dr. Wilhelm Hasselbring Kiel University, Germany Christian Wulf.
Protocol Derivation Assistant Matthias Anlauff Kestrel Institute
Test it! Unit, mocking and in-container Meet Arquillian! Ivan St. Ivanov.
MNP1163/MANP1163 (Software Construction).  Minimizing complexity  Anticipating change  Constructing for verification  Reuse  Standards in software.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Programming & Debugging. Key Programming Issues Modularity Modifiability Ease of Use Fail-safe programming Style Debugging.
EPSII Lecture Section AAA 1505 SC Professor Terry A. Braun Biomedical Engineering, Ophthalmology and Visual Sciences.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
Chapter 2 Introduction to OS Chien-Chung Shen CIS/UD
Lecture IX: Testing Web Services with Mocking CS 4593 Cloud-Oriented Big Data and Software Engineering.
ING XBRL Proof of Concept July 19, ©2005 page 2. Utilizing XBRL  ING Objectives  Benefits  Goals  Proof of Concept Plan  Stat  USGAAP  Pain.
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.
CSC 222: Object-Oriented Programming
CMSC 345 Defensive Programming Practices from Software Engineering 6th Edition by Ian Sommerville.
Mocking tools for easier unit testing
Eddie Jaquith Alexis Jarvis
Test Isolation and Mocking
Remote Method Invocation
CSC 222: Object-Oriented Programming
Managed Extensibility Framework
Mid-term Exam Account for 20% of the grade 100 points in total
EPANET-MATLAB Toolkit An Open-Source Software for Interfacing EPANET with MATLAB™ Demetrios ELIADES, Marios KYRIAKOU, Stelios VRACHIMIS and Marios POLYCARPOU.
Presented by: Jered Aasheim Tom Cornelius October 27, 2000
History, Characteristics and Frameworks
Java Programming Language
statically-typed JVM-targeted programming language
Designing For Testability
Chapter 2. Problem Solving and Software Engineering
Test-Driven Development
Software Engineering and Architecture
Final Review 27th March Final Review 27th March 2019.
Junit Tests.
Presentation transcript:

Mock Me If You Can An Introduction to the Mocking Framework Mockito Symposium on Software Performance 2014 Christian Wulf ― Software Engineering Group Kiel University, Germany

Motivation Mock Me If You Can - An Introduction to the Mocking Framework Mockito How to check that the underlying input stream is called only once? Christian Wulf ―

Motivation Mock Me If You Can - An Introduction to the Mocking Framework Mockito How to test a TcpReader‘s functionality without establishing a real TCP connection? Christian Wulf ― serverSocket socketChannel

Mockito Mock Me If You Can - An Introduction to the Mocking Framework Mockito Mockito library enables – mocks creation, – stubbing, and – verification Christian Wulf ― Started on Current version

When to Use Mock Me If You Can - An Introduction to the Mocking Framework Mockito When the CUD requires external (I/O) resources to work properly, e.g., – InputStream/OutputStream – ServerSocket/ClientSocket – File – Queue Christian Wulf ―

Mocking Methodology Mock Me If You Can - An Introduction to the Mocking Framework Mockito Setup Mocking a type instantiation Mocking a method call (a.k.a. stubbing) Assertion Verifying a method call Christian Wulf ―

Mocking Mock Me If You Can - An Introduction to the Mocking Framework MockitoChristian Wulf ― Mock=> types, i.e., interfaces, abstract classes, classes Spy => instances Necessary for verification

Stubbing Mock Me If You Can - An Introduction to the Mocking Framework Mockito doReturn(Object) doThrow(Throwable) – doThrow(new RuntimeException()).when(mockedList).clear(); doThrow(Class) doAnswer(Answer) doNothing() doCallRealMethod() Christian Wulf ―

Verifying Mock Me If You Can - An Introduction to the Mocking Framework Mockito verify(mockedList).add("one"); verify(mockedList).get(anyInt()); verify(mockedList, times(3)).add("three times"); verify(mockedList, atMost(5)).add("three times"); InOrder inOrder = inOrder(firstMock, secondMock); verify(mockOne, never()).add("two"); verifyZeroInteractions(mockTwo, mockThree); verify(mock, timeout(100).times(1)).someMethod(); Christian Wulf ―

Annotation-based Usage Mock Me If You Can - An Introduction to the Mocking Framework Mockito Minimizes repetitive mock creation code. Makes the test class more readable. Makes the verification error easier to read because the field name is used to identify the mock. Christian Wulf ―

Limitations Mock Me If You Can - An Introduction to the Mocking Framework Mockito Mockito doesn't mock final methods – AbstractInterruptibleChannel.close() Mockito doesn't mock static methods – ServerSocketChannel.open(); Christian Wulf ―

Conclusions Mock Me If You Can - An Introduction to the Mocking Framework MockitoChristian Wulf ― External resources InputStream/OutputStream ServerSocket/ClientSocket File Queue Alternative Mocking Framework for Java:

References Mock Me If You Can - An Introduction to the Mocking Framework Mockito Mockito: – PowerMock: – EasyMock – Christian Wulf ―