jstadni2 / pytest-fundamentals

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automated Software Testing with Pytest

This repository provides an interactive introduction to the pytest testing framework for Python.

Installation

The recommended way to install this repo is through git, which can be downloaded here. Once downloaded, execute the command:

git clone https://github.com/jstadni2/pytest-fundamentals

Next, download the appropriate Python installer for your machine. Make sure to add Python to PATH.

Run one of the following commands according to your operating system to install pytest.

macOS:

pip3 install -r requirements.txt

Windows (Powershell):

pip install -r requirements.txt

Visual Studio Code

While not essential for using pytest, this repo includes a demonstration of Visual Studio Code integration. The installer can be downloaded here. The Python extension for Visual Studio Code is required to run pytest test suites using the GUI.

What is Software Testing?

  • A process of evaluating and verifying whether software meets specified requirements and functions correctly
  • Detect bugs before they are encountered by users and ensure software is robust and performant
  • Prevent refactoring or additional features from breaking preexisting functionality (regression)

Software Testing Pyramid

image info source

  • Unit Tests: test the smallest testable part of the software (eg. a function, method, or class)
  • Integration Tests: test the interaction between different units or components
  • End-to-End Tests: test the entire system in a real-world scenario
  • As you move up the pyramid:
    • Execution time typically increases
    • Cost to implement/maintain increases

Why Automated Software Testing?

  • Run time-consuming or repetitive tasks more efficiently
  • Repeatable, consistent, and cost-effective
  • Allows for more comprehensive testing of edge cases
  • Can be integrated into Continuous Integration and Continuous Delivery pipelines (CI/CD)

Automated Test Steps

  1. Setup: Initialize data and create the preconditions needed to test specific functionality
  2. Act: Execute the function or system under test
  3. Assert: Compare the output or behavior of the software with the expected results
  4. Cleanup: Tear down test resources or revert state changes to prepare for subsequent tests

Topics

About


Languages

Language:Python 100.0%