mirror of
https://github.com/Brandon-Rozek/website.git
synced 2025-05-21 17:21:38 +00:00
New Post
This commit is contained in:
parent
fe6462e5c0
commit
a650fc940e
1 changed files with 39 additions and 0 deletions
39
content/blog/pyunittest.md
Normal file
39
content/blog/pyunittest.md
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
---
|
||||||
|
title: "Quick Python: Unit Testing"
|
||||||
|
date: 2020-03-31T07:27:47-04:00
|
||||||
|
draft: false
|
||||||
|
tags: ["python"]
|
||||||
|
---
|
||||||
|
|
||||||
|
Python has a great built-in [unit test](https://docs.python.org/3.7/library/unittest.html) framework. This post will give a skeleton for how to format the files in your `tests` directory.
|
||||||
|
|
||||||
|
Example `tests/test_basic.py`
|
||||||
|
|
||||||
|
```python
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class Tester(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
"""To Run Before Every Test Case"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""To Run After Every Test Case"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_something(self):
|
||||||
|
"""A Test Case"""
|
||||||
|
self.assertEqual(True, True)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
```
|
||||||
|
|
||||||
|
To auto-discover and run your tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python -m unittest discover
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue