Intimidating techniques

Rated 4.54/5 based on 592 customer reviews

Repeatability and isolation are key to these kinds of tests, even though we are still continuing with our theme of comparing expected outputs to actual outputs.

Now that you have an understanding of unit testing overall, you can take a quick detour and see how to unit test Flask applications with the minimum viable test suite.

While the logic in our code is fairly simple, it can easily grow in size and complexity, or become the responsibility of a whole team.

How do we test an application in a more structured, detailed, and automated way? Unit testing is a testing technique that breaks down source code into recognizable units (usually methods or functions) and tests them individually.

So now that we’ve gone probably a bit too deep into the theory, let’s look at how this works in practice.

Right now, the code doesn’t actually meet those expectations, so we will investigate using the four techniques while we are learning about them.

In all these situations and more, you will need to learn and get comfortable with the various methods for testing a Python CLI application.

While the tooling choices can be intimidating, the main thing to keep in mind is that you’re just comparing the outputs your code generates to the outputs you expect. In this tutorial you’ll learn four hands-on techniques for testing Python command-line apps: Everything will be structured around a basic Python CLI app that passes data in the form of a multi-level dictionary to two functions that transform it in some way, then prints it to the user.

When to use print debugging: Debuggers are great for when you want to step through the code one line at a time and inspect the entire application state.

They help when you know roughly where errors are happening but can’t figure out why, and they give you a nice top-down view of everything happening inside your application at once.

Leave a Reply