Reader small image

You're reading from  Learning Python Application Development

Product typeBook
Published inSep 2016
Reading LevelIntermediate
PublisherPackt
ISBN-139781785889196
Edition1st Edition
Languages
Right arrow
Author (1)
Ninad Sathaye
Ninad Sathaye
author image
Ninad Sathaye

Ninad Sathaye has spent several years of his professional career designing and developing performance-critical engineering applications written in a variety of languages, including Python and C++. He has worked as a software architect in the semiconductor industry, and more recently in the domain of Internet of Things. He holds a master's degree in mechanical engineering.
Read more about Ninad Sathaye

Right arrow

Unit tests using mock library


The two tests we wrote earlier were pretty straightforward to implement. Often, it is not trivial to write a test for verifying the functionality. The reasons could vary. In some scenarios, the code is required to be refactored in order to access the functionality you would like to test. In another scenario, the code might have dependencies that require you to write a lot more code than necessary. It is also possible that the functionality to be tested needs time consuming preparatory work such as crunching some numbers. This adds to the total test execution time. We will now learn how to write a unit test in such situations using the mock library. Before working on the actual code, let's understand what functionality this library provides.

Quick introduction to mock

The mock library provides a flexible way to create dummy objects that can be used to replace some parts in the program that you are testing.

Tip

Mock is available in the Python standard library ( v3...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Python Application Development
Published in: Sep 2016Publisher: PacktISBN-13: 9781785889196

Author (1)

author image
Ninad Sathaye

Ninad Sathaye has spent several years of his professional career designing and developing performance-critical engineering applications written in a variety of languages, including Python and C++. He has worked as a software architect in the semiconductor industry, and more recently in the domain of Internet of Things. He holds a master's degree in mechanical engineering.
Read more about Ninad Sathaye