Python writes test cases, unittest the six assertion methods in the TestCase class in the module, and the Setup () function.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.