python unittest 2 --- learn simple example

python unittest simple example as follows:

class TestString(unittest.TestCase):
    def test_upper(self):
        self.assertEqual("foo".upper(), "FOO")
     def test_isupper(self):
        self.assertTrue("FOO".isupper())
        self.assertFalse("Foo".isupper())
    def test_split(self):
        s="hello world"
        self.assertEqual(s.split(),["hello","world"])
        with self.assertRaises(TypeError):
        s.split(2)

if __name__=="__main__":
unittest.main()

 

Remarks:

1. Create a class, the class needs to inherit unittest.TestCase

2. This rule identified by the method of test cases need to start with a lowercase "test", because what is testcase testrunner

3.testrunner will be based on the implementation of test use case begins with the definition of the results after the convergence, and production reports, which are not assert statement

Guess you like

Origin www.cnblogs.com/dmtz/p/10967460.html