background image

unittest example

import unittest

class 

TestBuiltins

(

unittest.TestCase

):

    

"""Test some python built-in methods"""

    def 

test

_len

(self):

        self.

assertEqual

(5, len("hello"))

        self.

assertEqual

(3, len(['a','b','c']))

        

# edge case

        self.

assertEqual

(0, len(""))

    def 

test

_str_upper

(self):

        self.

assertTrue

( "ABC".isupper() )

        self.

assertFalse

( "ABc".isupper() )

        s = ""  

# edge case

        

self.assertFalse( s.isupper() )

class extends 

TestCase

Comments:

Unit Testing in Python

navigate_before navigate_next