Analysis of python automated test instances-Python tutorial

Source: Internet
Author: User
This article mainly introduces the python automated testing instance and analyzes the precautions in the instance. if you need it, refer to the example below to describe the python automated testing process, share it with you for your reference.

The code is as follows:

import unittest  ######################################################################## class RomanNumeralConverter(object):   """converter the Roman Number"""    #----------------------------------------------------------------------   def __init__(self, roman_numeral):     """Constructor"""     self.roman_numeral = roman_numeral     self.digit_map = {"M":1000, "D":500, "C":100, "L":50, "X":10,              "V":5, "I":1}        def convert_to_decimal(self):     val = 0     for char in self.roman_numeral:       val += self.digit_map[char]     return val    ######################################################################## class RomanNumeralConverterTest(unittest.TestCase):   """test class"""   def test_parsing_millenia(self):     value = RomanNumeralConverter("M")     self.assertEquals(1000, value.convert_to_decimal())    if __name__ == "__main__":   unittest.main()    

The program running effect is as follows:

.----------------------------------------------------------------------Ran 1 test in 0.000sOK 

Note the following three points:

1. import unittest
2. the test class must inherit unittest. Testcase.
3. call unittest. main () in main ()

Note that the test class also starts with test.

I hope this article will help you with Python programming.

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.