oswaldo.herrera@WIZELINE.com
@wdonet
import unittest
from sorters import InsertionSort # code from module you're testing
class SimpleTestCase(unittest.TestCase):
def runTest(self):
source = [6, 8, 12, 11, 15, 13, 20, 3, 10]
result = InsertionSort.sort(source)
assert len(source) == len(result), 'incorrect size'
self.assertEqual(result, [3, 6, 8, 10, 11, 12, 13, 15, 20])
AssertionError
setUp()
tearDown()
def setUp(self):
self.file = open("test-cases.xml", "r")
def tearDown(self):
self.file.close()
solo termina
Ejecuta Test
if __name__ == "__main__":
unittest.main() # run all tests
suite
import unittest
class SimpleWidgetTestCase(unittest.TestCase):
def setUp(self):
self.widget = Widget("The widget")
def test_default_widget_size(self):
assert self.widget.size() == (50,50), 'incorrect default size'
def test_widget_resize(self):
self.widget.resize(100,150)
assert self.widget.size() == (100,150), \
'wrong size after resize'
if __name__ == "__main__":
unittest.main() # run all tests
import unittest
class SimpleWidgetTestCase(unittest.TestCase):
def setUp(self):
self.widget = Widget("The widget")
class DefaultWidgetSizeTestCase(SimpleWidgetTestCase):
def runTest(self):
assert self.widget.size() == (50,50), 'incorrect default size'
class WidgetResizeTestCase(SimpleWidgetTestCase):
def runTest(self):
self.widget.resize(100,150)
assert self.widget.size() == (100,150), \
'wrong size after resize'
fixtures
Donde ?
src
README.md
LICENSE
setup.py
requirements.txt
sample
__init__.py
core.py
helpers.py
test_basic.py
test_advanced.py
src
README.md
sample1
__init__.py
core.py
sample2
__init__.py
helpers.py
tests
test_sample1.py
test_sample2.py
Misma suite
Ejecución automática
Acceden a datos simples o a ninguno
Suite diferente
Ejecutar en Scheduled Task
Acceden a una estructura de datos compleja
Pruebas de unidad
Habitos
square()
sum()
test_square_of_number_9()
test_square_of_negative_number()
test_sum_of_1_and_n()
test_sum_negative_number_greater_than_positive_number()
Nombres descriptivos de pruebas:
Módulo a probar
test_1()
test_must_work()
test_god_damn_fail()
No!
oswaldo.herrera@WIZELINE.com
twitter: @wdonet