We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Automatic Testing of Python Functions Based on Contracts

Formale Metadaten

Titel
Automatic Testing of Python Functions Based on Contracts
Serientitel
Anzahl der Teile
115
Autor
Mitwirkende
Lizenz
CC-Namensnennung - keine kommerzielle Nutzung - Weitergabe unter gleichen Bedingungen 4.0 International:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben.
Identifikatoren
Herausgeber
Erscheinungsjahr
Sprache

Inhaltliche Metadaten

Fachgebiet
Genre
Abstract
Good programs are correct programs. Testing is an indispensable tool making sure that the software we produce is correct. The bulk of today’s Python programs are tested using unit tests, on a case-by-case basis. While unit tests are important, thorough tests are tedious to write. A lot of edge cases need to be considered and human errors easily slip in. The edge cases are often simply omitted, e.g., for the lack of time. However, this leaves a lot of untested holes in the program. Instead of hunting for edge cases, what if we specified the behavior of a function and let the development tools test it for us? In this talk, we first look into how to specify the behavior of functions using contracts, i.e. the properties of the input and the output of a function. The contracts can reduce the amount of testing code, and allow the developer to focus on more tangible pieces of code, namely defining the behavior. Next, we examine two of our tools for automatic testing based on contracts (crosshair and icontract-hypothesis). We show how they can be used in everyday programming with little additional effort. A corpus of programs (Python-by-contract) is introduced to evaluate where the tools shine and what limitations they hit. Finally, we show how to use the tools in the classroom to help students with debugging, providing hopefully a better educational experience. The talk is aimed at Pythonistas familiar with lambda functions, Boolean logic (“and”, “or”) and quantifiers (“all”, “any”).