Brucester
Brucester

Reputation: 49

Why does the Python unittest doc contradict itself?

The Python unittest doc defines a test case as:

"[...] the smallest unit of testing. It checks for a specific response to a particular set of inputs."

However the first example contains a method with two assertions:

def test_shuffle(self):
    ...
    self.assertEqual(self.seq, range(10))
    ...
    self.assertRaises(TypeError, random.shuffle, (1,2,3))

This is clearly a contradiction, since the assertions each contain their own inputs and expected response.

Which approach is most appropriate?

Upvotes: 0

Views: 62

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375484

Having two assertions is not a problem in and of itself. But the first example in the docs does test two separate things, and should be split into smaller pieces.

The question of how finely to slice your tests can become a philosophical one. Find a balance that feels right to you.

Upvotes: 1

Related Questions