【问题标题】:Is there a convention to distinguish Python integration tests from unit tests?是否有区分 Python 集成测试和单元测试的约定?
【发布时间】:2013-03-16 09:04:19
【问题描述】:

使用单元测试构建 Python 包的最常见方法如下:

package/
    __init__.py
    module_1.py
    module_2.py
    module_n.py
    test/
        __init__.py
        test_module_1.py
        test_module_2.py
        test_module_n.py

我想区分单元测试(方法和函数)和集成测试(使用整个包并可能涉及其他资源)。也许这些测试应该在不同的包中,有不同的文件名,和/或包含某些文档字符串 cmets。

是否有执行此操作的标准约定?

【问题讨论】:

    标签: python unit-testing integration-testing


    【解决方案1】:

    我刚刚自己研究了一下,发现 this suggestion 很有帮助:

    project/
    │
    ├── my_app/
    │   └── __init__.py
    │
    └── tests/
        |
        └── unit/
        |   ├── __init__.py
        |   └── test_sum.py
        |
        └── integration/
            |
            ├── example_data/
            |   ├── test_basic.json
            |   └── test_complex.json
            |
            ├── __init__.py
            └── test_integration.py
    

    【讨论】:

      【解决方案2】:

      在我们的项目中,我们在每个包中都有单元测试,与您的情况相同,集成测试,系统测试,作为顶层的单独包,即:

      package_1/
        __init__.py
        module_1.py
        module_n.py
        test/
          __init__.py
          test_module_1.py
          test_module_n.py
      package_n/
        __init__.py
        module_1.py
        module_n.py
        test/
          __init__.py
          test_module_1.py
          test_module_n.py
      systemtest/
        __init__.py
        systemtest_1.py
        systemtest_n.py
      

      即使您在项目中只有一个包,我也会使用此约定。但是我不确定这是否是标准约定。

      【讨论】:

      • 我真的很想在那个包中保留一个包的集成测试。
      • 在这种情况下,我会在你的包之外创建 2 个单独的子包(一个称为 test,一个称为 systemtest),但这绝对不是惯例,而是我的猜测。
      • @JaceBrowning:这不是“集成测试”的一部分,可能涉及多个包吗?在这种情况下,该测试的位置应该高于任何单元测试。
      • @ChristophJüngling,“其他资源”我指的是文件和网络 IO 之类的东西——通常应该在单元测试中模拟但包含在集成测试中的东西。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 1970-01-01
      • 2011-02-06
      • 2016-01-23
      • 1970-01-01
      • 2011-07-18
      • 2013-03-18
      相关资源
      最近更新 更多