zoukankan      html  css  js  c++  java
  • pythonunittest(1)

    一个非常简单的python的测试用例,取自电子书:《Python Testing Cookbook》第一章内容,里面说的足够简单明了,将之摘出来,对照代码,应该很容易理解。

    The basic concept of an automated unittest test case is to instantiate part of our code,
    subject it to operations, and verify certain results using assertions.
    1. If the results are as expected, unittest counts it as a test success
    2. If the results don't match, an exception is thrown and unittest counts it as a
    test failure
    With these steps, we will code a simple program and then write some automated tests
    using unittest:

    1. Create a new file called recipe1.py in which to put all of this recipe's code. Pick a
    class to test. This is known as the class under test. For this recipe, we'll pick a class
    that uses a simplistic Roman numeral converter:

    2. Write a new class and give it the same name with Test appended to the end,
    subclassing unittest.TestCase. Appending a test class with Test is a common
    convention, but not a requirement. Extending unittest.TestCase is a requirement
    needed to hook into unittest's standard test runner.

    3. Create several methods whose names start with test, so they are automatically
    picked up by the test number of unittest.

    4. Make the entire script runnable and then use unittest's test runner.
    if __name__ == "__main__":
    unittest.main()

    5. Run the file from the command line.

    附测试代码:

    Code

     
    运行结果:

    ........
    ----------------------------------------------------------------------
    Ran 8 tests in 0.001s

    OK

  • 相关阅读:
    scrapy爬虫系列之三--爬取图片保存到本地
    scrapy爬虫系列之四--爬取列表和详情
    python3.7.2 ssl版本过低导致pip无法使用的问题
    python3安装后无法使用退格键的问题
    位运算符和unity Layers
    unity常用小知识点
    unity -- Time类(持续更新中)
    随便说说 post-processing
    unity图片后期处理
    顶点/片元 shader 总结
  • 原文地址:https://www.cnblogs.com/luhouxiang/p/2560029.html
Copyright © 2011-2022 走看看