Writing and debugging code is hard, but testing shouldn't be. This talk will discuss common techniques for writing simpler tests that still exercise your production code while preventing you from spending time debugging test code.
['name', 'value', 'units']) def lines_to_tuples(filename): tuples = [] with open(filename, 'r') as file_obj: for line in file_obj: fields = line.split() tuples.append(entry(*fields)) return tuples References: http://bit.ly/dumber_tests_pytx2014
of testing that the code does what the code says it does, rather than testing functional behavior we care about." -- Daniel Pope, "Every mock.patch is a little smell" References: http://bit.ly/dumber_tests_pytx2014
test_shuffle(self): # make sure the shuffled sequence does not lose any elements random.shuffle(self.seq) self.seq.sort() self.assertEqual(self.seq, range(10)) # should raise an exception for an immutable sequence self.assertRaises(TypeError, random.shuffle, (1,2,3)) def test_sample(self): with self.assertRaises(ValueError): random.sample(self.seq, 20) for element in random.sample(self.seq, 5): self.assertTrue(element in self.seq) References: http://bit.ly/dumber_tests_pytx2014
people, people not schooled in the details of your implementation, you can learn how to make your work easier to absorb, and therefore more effective at what it's designed to do. -- Dave Winer, Early author of RSS software References: http://bit.ly/dumber_tests_pytx2014