zoukankan      html  css  js  c++  java
  • python测试框架nose

    据说nose是一个比较牛逼的单元测试框架,今天打算来学习学习。

    nose不是python自带模块,这里我才用pip的方式安装

    pip install nose

     

    这样就完成了安装,然后再确认下是否安装成功了,直接打开cmd输入nosetests

     

    出现这个一般就说明安装成功了。

     

     

    好了,下面是正戏:

    nose相关执行命令:

    1、  nosetests  –h查看所有nose相关命令

    2、  nosetests –s执行并捕获输出

    3、  nosetests –with-xunit输出xml结果报告

    4、  nosetests -v: 查看nose的运行信息和调试信息 

    5、  nosetests -w 目录:指定一个目录运行测试

     

    nose 特点:

    a)         自动发现测试用例(包含[Tt]est文件以及文件包中包含test的函数)

    b)         以test开头的文件

    c)         以test开头的函数或方法

    d)         以Test开头的类

    经过研究发现,nose会自动识别[Tt]est的类、函数、文件或目录,以及TestCase的子类,匹配成功的包、任何python的源文件都会被当做测试用例。

     

    下面写一个简单的测试用例

    # coding = utf-8
    # author:semishigure
    
    
    class Testclass:
    
        def __init__(self):
            pass
    
        def setup(self):
            print 'start'
    
        def teardown(self):
            print 'stop'
    
        def testfunc1(self):
            print 'this is case1'
    
        def testfunc2(self):
            print 'this is case2'
    
        def testfunc3(self):
            print 'this is case3'

    执行结果如下:

  • 相关阅读:
    Win10 ntoskrnl.exe蓝屏解决
    Log POST Data in Nginx
    MACOS关闭指定端口
    获取Skype用户IP地址
    禁止windows10带来的三大隐患问题
    各种语言一句话反弹shell
    2015阿里巴巴安全峰会PPT
    HTTPS反向代理嗅探
    利用arpspoof和urlsnarf 进行ARP嗅探
    收集的几个存在漏洞的程序
  • 原文地址:https://www.cnblogs.com/semishigure/p/7268251.html
Copyright © 2011-2022 走看看