2. Example test with parameterized decorator
import unittest
from nose_parameterized import parameterized
class AddTestCase(unittest.TestCase):
@parameterized.expand([
("2 plus 3", 2, 3, 5),
("3 plus 5", 3, 5, 8),
])
def test_add(self, _, a, b, expected):
self.assertEqual(a + b, expected)
3. Dynamically created tests
$ nosetests example.py --verbosity=2
test_add_0_2_plus_3 (example.AddTestCase) ... ok
test_add_1_3_plus_5 (example.AddTestCase) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK
4. Some Use Cases
● Write less code to generate many tests with different parameters
● We use it at SimpleLife to test 15 different scenarios of a django FormWizard
view that has 7-8 steps
○ (given inputs [a,b,c,...], we expect to see [x,y,z,..]
● Use it to test APIs
○ input is JSON blob X, expect JSON blob Y as output