Testing fundamentals in Python

 The main focus of this series would be to provide a possible approach for ensuring a complete validation in Python no matter the layer. We will feel its flavor on testing covering different libraries.

 Based on the testing pyramid, there are 3 main layers to be covered through Python and just on top of them, the manual testing comes in.

The pyramid in details

  1. Unit testing
    1. Goal: The primary motion of the unit tests is to ensure that each piece/unit of code is validated against the requirements. Additionally, following some best practices, it can guide the developer on what to do, facilitate teamwork and code understanding
    2. Possible solutions
      1. The built-in unittest module
      2. Pytest
    3. Ensure a specific % of the code is validated using the coverage module
    4. As a technic it’s a purely white box one, this being said, we need visibility towards the source code, so there is no doubt that it’s dev responsibility to implement them
  2. Integration testing
    1. For sure we can catch lots of bugs using unit tests, but what happens when you mix together two different functions. If you want to check the compatibility you will need to perform those checks.
    2. It still needs visibility to the code, so it’s a while box method again, but in terms of responsibilities, it can be split between dev and QA automation
    3. The approach which will be covered in the next tutorial  is BDD based (Behaviour Driven Development) using behave package with a mix of pytest behind
  3. End to end testing
    1. The last but not least validation check which is mandatory to be performed is the end-to-end one. Here there are more testing techniques that are recommended to be followed.
      1. Functional
        1. We will check against the requirements if the application works correctly. As a guideline, the automated tests should follow the exact steps provided in a test management tool
        2. For this part, we will use mainly Selenium and behave as a short overview on how to approach BDD on the top of the pyramid.
      2. Non-functional
        1. Performance Testing. Measure how the application can face different challenges (how it behaves under different circumstances)
        2. Security – check our software vulnerabilities against different attacks. A simple approach to monitoring the network through Python.
        3. Localization – check the adaptability of an application for some specific regions, cultures. We will make usage of Selenium + image processing techniques
      3. The testing methods from this category, don’t forget that are black-box methods, as we don’t see the source code.


As we’ve noticed, there are several testing methods to be considered while building a product, and all of them can be done in Python. Of course on the white box side, if your code was build in C++ or Java, it would be better to follow the native language, but from the black box perspective, there is no limitation. In the next part, we will dive more into details about each layer. The first one will be around unit testing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.