https://github.com/virtualbrainlab/automated-unit-testing-demo
Demo repo for automated unit testing in Python. Use this as a reference for how to perform unit tests in Python and have GitHub Actions run them.
https://github.com/virtualbrainlab/automated-unit-testing-demo
github-actions python unit-testing
Last synced: about 1 month ago
JSON representation
Demo repo for automated unit testing in Python. Use this as a reference for how to perform unit tests in Python and have GitHub Actions run them.
- Host: GitHub
- URL: https://github.com/virtualbrainlab/automated-unit-testing-demo
- Owner: VirtualBrainLab
- License: gpl-3.0
- Created: 2023-08-22T17:36:10.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-31T21:42:05.000Z (almost 3 years ago)
- Last Synced: 2025-02-15T23:42:24.583Z (over 1 year ago)
- Topics: github-actions, python, unit-testing
- Language: Python
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Automated Unit Testing Demo
[](https://github.com/VirtualBrainLab/automated-unit-testing-demo/actions/workflows/test.yml)
Demo repo for automated unit testing in Python. Use this as a reference for how to perform unit tests in Python and have
GitHub Actions run them.
## Install and run the demo code
1. Clone this repo: `git clone https://github.com/VirtualBrainLab/automated-unit-testing-demo.git`
2. (Optional) create a virtual environment: `python -m venv venv`
3. Install the package: `pip install -e .`
4. Run the demo script: `demo`
5. Run the unit tests: `python -m unittest discover -s tests`
## Work through writing tests
This repo has branches labeled `0-...` through `5-...` which highlight steps in the process of writing code and unit
tests. They can be visited (in no particular order) with `git checkout` or `git switch` to experiment wth writing tests
and see the code at different states. On the `main` branch you can see the finished product including GitHub Actions
workflow and branch protection.
| Branch | Description | Activity |
|------------------|------------------------------------------------------------------------------|---------------------------------------------------|
| `0-start` | Demo class code with no unit tests. | Write tests for `DemoClass` from scratch. |
| `1-weak-tests` | Basic unit test. Demonstrates the `TestCase` class structure. | Improve the tests given. |
| `2-code-change` | `DemoClass`'s code got changed! Does the unit tests catch the bugs (if any)? | Write tests to catch the bugs introduced. |
| `3-better-tests` | Improved unit tests to expose the bugs. | Fix the bugs introduced in `DemoClass` |
| `4-fixed-code` | Fixed the bugs introduced earlier. | Think of inputs that can trigger uncaught errors. |
| `5-error-tests` | Added tests that check for bad inputs. | Write a GitHub Action workflow from scratch. |