in Python by
What is Assert Methods in unittest of Python?

1 Answer

0 votes
by
Till now, you have seen usage of basic assertions like assertEqual , and assertTrue.

In addition to these assertions, unittest supports usage of various assertions, which are handy to verify to various testing conditions.

The purpose of various assertions can easily be understood from their names it's self.

For e.g, the assertion assertIsNone(x), checks if the variable x is None.

Majorly Used Assert Methods

Frequently used assert methods in unittest are:

assertEqual(a, b) - Tests if a equals to b

assertAlmostEqual(a, b) - Tests if round(a-b, 7) is 0.

assertTrue(x) - Tests if bool(x) is True.

assertIs(a, b) - Tests if a is b.

assertIsNone(x) - Tests if x is None

assertIn(a, b) - Tests if a in b

assertIsInstance(a, b) - Tests if a is an instance of b.

assertRegexpMatches(s, r) - Tests if the regular expression pattern r is found in string s.

assertItemsEqual(a, b) - Tests if sorted(a) equals to sorted(b)

assertListEqual(a, b) - Tests if two lists a and b are same.

assertMultiLineEqual(a, b) - Tests if two multiline strings a and b are equal.
...