Hacker News new | ask | show | jobs
by dnsauve 6075 days ago
One way I've always dealt with the repetitive bits in my tests is to break out the offending code into separate utility type methods that can then be called by the test itself (or even multiple tests) as needed.

These methods could themselves also contain assertThis, assertThat, as needed to ensure they're functioning as expected as well.

Another way I've done it is to have tests calling other test methods themselves. i.e., something like:

    testFoo(self):
       # Do some test here.
       self.assertTrue(....)

    testBar(self):
       # Test that Foo works for logged in user as well
       self.client.login(username='joe', password='abc')
       self.testFoo()
       self.assertTrue(...)
1 comments

I think at least one or a combination of these methods will resolve my qualms with how it's arranged right now. Thank you very much.

Edit: It is worth noting that I'm trying to keep the unit tests independent, however.