Unit Testing (Python)
Unit testing sample
Function example functions.py
#!/usr/bin/env python3
def hello_world():
return "Hello world! =D"
Test example test.py (Standard library already includes unittest module)
#!/usr/bin/env python3
import unittest
from functions import hello_world
class TestHelloWorld(unittest.TestCase):
def test_string_match(self):
self.assertEqual(hello_world(), "Hello world! =D")
if __name__ == '__main__':
unittest.main()
Run the test!
python3 test.py
Assumed project structure
myProject/
├── functions.py
└── test.py