0

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?

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.