[Pycon] [new paper] "Sunaina Pai" - Mastering Mock Object Library to Write Better Unit Tests
info a pycon.it
info a pycon.it
Dom 6 Gen 2019 18:55:04 CET
Title: Mastering Mock Object Library to Write Better Unit Tests
Duration: 45 (includes Q&A)
Q&A Session: 15
Language: it
Type: Talk
Abstract: Python comes with unittest package that provides a very comprehensive unit testing framework for writing unit tests. Often, the functionality being tested depends on complex objects that are unnecessary and/or impractical to create in unit tests. That's when we need to use mock objects to partially simulate the behaviour of the real objects in order to write the unit tests and invoke the functionality being tested. Sometimes we also need to validate whether the functionality being tested exercised the mock objects in certain ways. Python comes with a quite comprehensive mock object library too in the form of unittest.mock module that fulfill these requirements of mocking objects.
This talk would discuss how to use the unittest.mock library to create mock objects, patch modules and classes, recording method calls on objects, and make assertions about which methods or attributes were used, the number of times they were called, and the arguments they were called with. Additionally, this talk would also discuss how to construct complex mock objects that simulate specific expected behaviour such as returning specific values, possessing certain attributes, triggering side effects such as raising exceptions, etc.
The goal of this talk is to help developers with a basic knowledge of unit testing to master how to effectively mock objects to write better, simpler, and robust unit tests. A basic knowledge of Python and unit testing is expected to understand this talk.
Tags: [u'#mock', u'#unittest', u'#software-development']
Maggiori informazioni sulla lista
Pycon