DEV Community

Qiwen Yu
Qiwen Yu

Posted on

Add Tests to Project

Overview

The job of this week was to manage project complexity through the use of Automated Testing. Writing test cases, from unit test, integration test, to test driven development (TDD), is very important. Without any tests, code will be broken, and no one has any way to know it.

To assure ourselves and others that our software works, we write automated tests. These are programs that automatically run certain inputs through other programs or parts of programs.

Python tests rarely check types. They check values.

Pytest for unit testing

Unit tests focus on testing the least amount of code possible in any one test. Pytest uses the assert statement to verify results. This makes tests simpler, more readable, and, consequently, easier to maintain. When we run pytest, it starts in the current folder and searches for any modules or sub packages with names beginning with the characters test_, (Including the _ character.) functions start with test, classes start with Test, and folder named tests.

SSG (static site generator) project

Thus, in this work, first, I refactored the project again to have a tests subfolder, and all other changes to setup a better framework of the whole package for testing. Moreover, the corresponding contributing.md was also modified.

Finally, test cases were written to test core functionality of SSG, including get_title and generating .html from .txt files. With the help of unit test cases, the original code was updated to have a better format of html page.

Discussion (0)