如何使用鼻子测试分别组织和运行单元测试和功能测试 [英] How to organize and run unittests and functional tests separately using nosetests

查看:112
本文介绍了如何使用鼻子测试分别组织和运行单元测试和功能测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下典型的python项目文件结构

I have the following typical python project file structure

packageA
   +----subpackage1
            +----classa.py
   +----subpackage2
            +----classb.py
   +----test
          +----subpackage1
                    +----classa_test.py 
          +----subpackage2
                    +----classb_test.py

我目前正在尝试组织单元测试和功能测试,因此我可以使用鼻子分别运行单元测试和功能测试,但也可以选择运行所有测试.这些测试将存在于packageA/test/subpackage1和packageA/test/subpackage2中.

I am currently trying to organize my unittests and functional tests so I can run unittests and functional tests separately using nose but also have the option to run all tests. The tests would live in packageA/test/subpackage1 and packageA/test/subpackage2.

  • 组织不同测试的好方法是什么?按文件夹(功能/vs单位/)?通过测试类的命名约定(ClassATest与ClassAFunctionalTest)?还是通过命名测试方法的约定(classa_foo_test与classa_bar_functional_test)?
  • 有人可以解释一下鼻子测试的正则表达式匹配如何工作吗?选项-m,-i和-e似乎没有按我期望的方式运行.正则表达式是否匹配目录(subpackage1),文件(classa_test)或测试类(ClassATest)或测试方法(classa_foo_test)?我非常困惑

推荐答案

我的测试目录结构如下:

My tests directory structure looks this way:

root
  + --- tests
  |       + --- unit_tests
  |       |         + --- some_app_tests   
  |       |         + --- another_app_tests
  |       |         | run_tests.py
  |       |
  |       + --- integrate_tests 
  |                 + --- some_app_tests
  |                 + --- another_app_tests
  |                 | run_tests.py
  |       
  + --- project_root
          + --- some_app
          + --- another_app

对于每个单独的应用程序,我在unit-和integration-目录中创建带有测试的coresponding目录.每个目录都是具有自定义设置的独立django项目,其中包含用于运行测试的管理命令.

For each individual app I create coresponding directory with tests in unit- and integrate- directory. Each is directory is separate django project with custom settings and there's management command used to run tests.

还将测试放在一个目录中有一个很好的优点-部署项目时,没有理由使用它来部署测试.所以我只剥离一个目录就可以了.

Also placing tests in one directory has one nice advantage - when project is deployed, there's no reason to deploy tests with it. So I just strip one directory and that's all.

(要运行测试,我使用django-sane-testing: https://github.com/Almad/django-sane-testing )

(to run tests I use django-sane-testing: https://github.com/Almad/django-sane-testing )

这篇关于如何使用鼻子测试分别组织和运行单元测试和功能测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆