python测试框架nose研究_python 测试框架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的源文件都会被当做测试用例。

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

 

Main.py

1 importnose2

3 #nose.main()

4

5 result=nose.run()6

7 print(result)

test1.py

1 defTestfunc():2

3 a = 1

4

5 b = 1

6

7 assert a == b

test2.py

1 #coding = utf-8

2

3 #author:semishigure

4

5 classTestclass:6

7 def __init__(self):8

9 pass

10

11 defsetup(self):12

13 print 'start'

14

15 defteardown(self):16

17 print 'stop'

18

19 deftestfunc1(self):20

21 print 'this is case1'

22

23 deftestfunc2(self):24

25 print 'this is case2'

26

27 deftestfunc3(self):28

29 print 'this is case3'

执行结果如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值