UnitTest is a module in the standard library that comes with Python, which includes:
1, TestCase class
2, Testsuite class
3, Testloader class
4, Texttestrunner class
5, Texttestresult class
The following are the test cases for the six assertion methods in TestCase.
#-*-Coding:utf-8-*-
Import UnitTest
Class Teststringmethods (UnitTest. TestCase):
def test_one (self):
"Test two strings for equality"
string = ' haha '
Self.assertequal (String.title (), ' Haha ')
def test_two (self):
"Test two strings are not equal"
string = ' haha '
Self.assertnotequal (String, ' Haha ')
def test_three (self):
"' Test whether the string is False '
string1 = ' haha '
Self.assertfalse (String1.isupper ())
def test_four (self):
"' Test if the string is true '
string2 = ' haha '
Self.asserttrue (String2.islower ())
def test_five (self):
"' Test string is in the list '"
string = [' haha ', ' heihei ', ' hehe ']
str = ' Heihei '
Self.assertin (str,string)
def test_six (self):
"' Test string is not in the list '"
string = [' haha ', ' heihei ', ' hehe ']
str = ' HoHo '
Self.assertnotin (str,string)
Unittest.main ()
Python writes test cases, unittest the six assertion methods in the TestCase class in the module, and the Setup () function.