Unit Test Methods

You’ll learn about the unit test methods available in Python in this lesson.

We'll cover the following

Introduction to unit test methods

The following are some of the methods available in unittest, most of which are self-explanatory.

  • assertEqual(a, b)

  • assertNotEqual(a, b)

  • assertAlmostEqual(a, b) for floating point numbers

  • assertAlmostEqual(a, b, places)

  • assertTrue(x)

  • assertFalse(x)

  • assertIs(a, b) tests for identity

  • assertIsNot(a, b)

  • assertIsNone(x)

  • assertIsNotNone(x)

  • assertIn(a, b)

  • assertNotIn(a, b)

  • assertIsInstance(a, b)

  • assertNotInstance(a, b)

  • assertRaises(exception, function, arguments)

All calls to these methods must be prefixed with self..

Each of these methods has an optional final parameter, which may be any expression. The final parameter is used as a message in the AssertionError to provide any necessary additional information.

Get hands-on with 1400+ tech skills courses.