【问题标题】:How do I separate between integration testing and unit testing using Hapi in Node.js?如何在 Node.js 中使用 Hapi 区分集成测试和单元测试?
【发布时间】:2022-12-16 23:40:27
【问题描述】:

如何在 Node.js 中使用 Hapi 区分集成测试和单元测试?

每当我们在 API 中更新一个单元时,我都试图减少自动化测试的时间。

我想知道我是否可以创建两个新文件夹 test/unit 和 test/int 来分隔脚本以及 package.json 的更新需要什么?

我在运行 .labrc.js 的 package.json 中有以下内容 包.json

    "test": "npm run version-stamp && lab --bail -t 80 -r html -o coverage.html -r console -o stdout -r junit -o TestResult.xml -r lcov -o coverage.dat",
    "simple-test": "npm run version-stamp && lab",
    "test-int": "not sure what to put here",

labrc.js

module.exports = {
    verbose: true,
    timeout: 7500,
    lint: true,
    paths: [
        "test/init/aws",
        "test/unit/plugins",
        "test/unit/utils",
        "test/unit/routes"
    ],

【问题讨论】:

    标签: node.js unit-testing jestjs nunit hapi.js


    【解决方案1】:

    当然你的方法听起来不错。问题是 lab 不允许自定义 labrc 为集成测试指定不同的路径。但你可以尝试做这样的事情

    在两个不同的目录中单独测试

    • test/unit
    • test/integration

    为集成测试提供额外的替代 labrc.js 配置文件,并删除根目录中可用的配置文件,

    你将有两个不同的labrc.js文件

    • test/unit/labrc.js
    • test/integration/labrc.js

    单元测试的应该看起来像

    test/unit/labrc.js

    module.exports = {
        verbose: true,
        timeout: 7500,
        lint: true,
        paths: [
            "unit/plugins",
            "unit/utils",
            "unit/routes",
        ],
    

    为了集成测试

    test/unit/labrc.js

    module.exports = {
        verbose: true,
        timeout: 7500,
        lint: true,
        paths: [
            "integration/aws",
        ],
    

    在 package.json 中

    {
        ... Lot of JSON config here
        "test": "npm run version-stamp && lab test/unit --bail -t 80 -r html -o coverage.html -r console -o stdout -r junit -o TestResult.xml -r lcov -o coverage.dat",
        "simple-test": "npm run version-stamp && lab test/unit",
        "test-integration": "lab test/integration", 
        ... Further JSON config here
    }
    

    自定义传递给实验室的参数

    作为建议更喜欢一体化超过整数这可能令人困惑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-15
      • 2011-02-06
      • 2016-01-23
      • 2016-10-03
      • 1970-01-01
      • 2019-07-20
      • 2011-12-11
      • 2013-10-23
      相关资源
      最近更新 更多