[Tutor] TDD in Python
angela ebirim
cebirim at gmail.com
Mon Sep 26 16:54:18 EDT 2016
Hello everyone,
I'm a new member on this maling list and am in the process of learning
python.
I'm keen to learn about testing my Python code and hoping someone could
help me with this query...
#test.py
class Test:
def __init__(self, members):
self.members = members
def printMembers(self):
print('Printing members of Test class...')
for member in self.members: print('\t%s ' % member)
test = Test(['Gazelle', 'Elephant', 'Lion', 'Fish'])
test.printMembers()
#test_test.py
import unittest
from test import Test
class TestTestCase(unittest.TestCase):
"""Tests for `test.py`."""
#preparing to test
def setUp(self):
"""Sample test case"""
print "TestTest::setUp_:begin"
# self.members = [1, 2, 3, 4, 5]
self.members = Test([1, 2, 3, 4])
def test_is_printMembers(self):
"""Will print a list of contents?"""
self.assertTrue(self.members.printMembers)
if __name__ == '__main__':
unittest.main()
Does my test code in test_test.py look correct?
Many thanks
More information about the Tutor
mailing list