Reputation: 1926
When testing a single function with different inputs (some that are default), is it better practice to do:
def test_init(self):
page = HTMLGen("test", "path\\goes\\here")
self.assertEqual(page.path, "path\\goes\\here\\index.html")
page_2 = HTMLGen("test", "path\\goes\\here", "cool_page")
self.assertEqual(page_2.path, "path\\goes\\here\\cool_page.html")
or
def test_init(self):
page = HTMLGen("test", "path\\goes\\here")
self.assertEqual(page.path, "path\\goes\\here\\index.html")
def test_init_with_filename(self):
page = HTMLGen("test", "path\\goes\\here", "cool_page")
self.assertEqual(page.path, "path\\goes\\here\\cool_page.html")
Upvotes: 2
Views: 782
Reputation: 310257
The second approach is better because if the first test fails, the second one will still have a chance to run. This can give you more information for tracking down exactly where the bug is happening and what is causing it.
Additionally, any cleanup/teardown code will be run between the tests which can help to guarantee that the tests are independent.
Upvotes: 3