|Recommended Duration||3 days (minimum 6 hours + breaks each day)|
|Requirements||basic Python skills|
|Intended Audience||Python Developers, Testers|
|Language||Polish or/and English|
|Main Technologies||Unittest, Doctest, nose2, behave, webtest, mock|
This workshop covers all aspects of automated testing in Python. It focuses a lot on two methodologies: Test Driven Development and Behavior Driven Development. It covers test isolation, mocking, a wide range of testing frameworks and tools (unittest, doctest, nose2, behave, nose2.tools.such, webtest among others) as well as an overview of unconventional testing approaches and code coverage.
Have a look at a sample of this workshop – live coding of Recently Used List Kata.
First day: Test Driven Development
SOLID. We start from a discussion on SOLID principles that makes code easier to read and maintain. This part is supplemented with exercises showing how to apply (and how not to do this) SOLID in Python. This will be helpful in the second step of each iteration in TDD (as well as BDD), that is writing production code.
Code refactoring. The third step of each iteration in both TDD and BDD is refactoring, that is making code easier to read and maintain without changing its functionality.
In this part, we cover all building blocks (or actions) of refactoring. We introduce the concept of code bad smells that help you find opportunities for correct refactoring and avoid “endless refactoring back and forth”.
Builtin testing frameworks. First step of each iteration in TDD is writing a test.
We start from a discussion if and why writing tests is beneficial. Contrary to intuition, less bugs is only one of the advantages of covering code with tests.
We usually use a framework that makes writing tests easier. We show how to use the most popular testing framework – unittest.
We also introduce very agile doctest library which help you test, and at the same time, document small utility functions without all the burden and long-winded unittest.
Test Driven Development. After short theoretical introduction to TDD, we solve Katas – programming challenges like RecentlyUsedList or BowlingGame. Katas are simple exercises that let you focus on the TDD methodology rather than fighting with language, IDE or business logic.
We start from a live coding - the instructor shows how you can solve a Kata using TDD. Participants ask questions and discuss with the instructor and other participants. Later on, we move to another Kata. This time participants do the exercise in pairs (pair programming).
Second day: mocking
Test isolation and mocking is covered during second day of the training. We introduce great unittest.mock builtin library (or mock backport if you work on Python 2). It helps you isolate your tests from system calls, filesystem, databases, external APIs or any other resources. We study the most common cases.
Mocking is also an essential part of outside-in development which is covered during the last day.
Testing web application let you focus on one of common cases when you need to test a web application written using a framework. For simplicity, this framework is Flask unless you work in Django, in which case we focus on Django’s own challenges.
A number of tools are discussed, Selenium and builtin Flask client being two of them. However, we introduce and focus on WebTest which is other client and is much faster than Selenium.
We also show how professional edition of PyCharm supports testing web frameworks.
Overview of other testing approaches. At the end of the day, the instructor introduces other testing approaches. We discuss property-based testing (with hypothesis-python library) and mutation testing (with MutPy). We also introduce a concept of code coverage and show how to configure it.
Third day: BDD
Outside-in Development. Most of the time, programmers develop their code inside-out. They start from the simplest functions and tools (inner or lower modules), maybe even they test them, and built outer (or higher) modules upon them. For example, they first implement backend, and then frontend. This is dictated by the fact that the outer modules depend on the lower ones, for example frontend depends on backend. Therefore, you cannot test outer ones without inner ones.
However, this results in bad interfaces, because outer modules are written to match inner modules instead of required behavior. Outside-in development forces you to first implement higher modules, test them mocking the lower modules, and then focus on the inner modules. This results in better interfaces between modules.
Plain-text stories in Gherkin. We introduce a special domain specific-language based on English natural language that helps you write acceptance tests understandable for non-programmers. If you have ever heard about Cucumber, you’ll be astonished that there is a very similar framework in Python called behave.
nose2.tools.such DSL. We introduce another style of BDD - executable specification written with nose2.tools.such plugin, a DSL in Python.
We also introduce nose2 tool to run unit tests and show how you configure it and enable nose2.tools.such plugin.
Behave Driven Development is an extension of TDD. After a short theoretical introduction, we show on a case study how you can use behave and nose2.tools.such with BDD. We also show how professional edition of PyCharm supports BDD and behave framework.
In this part, as an exercise, you implement an entire web application talking to an external API using BDD methodology. That means that you put into action all the knowledge and skills you learned through entire course, especially mocking.
Are you interested?
Don’t hesitate to contact me if you’re interested or you want to ask a question. You can expect:
No risk – if you were disappointed after my workshop, you would not pay for it.
A customized syllabus after a free discovery call. During the call, I’ll analyze your needs and we’ll decide on next steps. Please include your availability for the call.