background image

What Can You assert?

assertTrue

( gcd(-3,-5) > 0 )

assertFalse

( "hello".isupper() )

assertEqual

( 2*2, 4)

assertNotEqual

( "a", "b")

assertIsNone

(a)

           

# test "a is None"

assertIsNotNone

(a)

        

# test "a is not None"

assertIn

( a, list)

        

# test "a in list"

assertIsInstance

(3, int)

  

# test isinstance(a,b)

assertListEqual

( list1, list2 ) 

# all elments equal

Many more!

See "unittest" in the Python Library docs.

Comments:

Unit Testing in Python

navigate_before navigate_next