测试报告如何添加

在项目中一般都会添加自动化测试,为了知道开发写的测试覆盖率,加入了测试报告,具体配置如下:

server test

使用mocha run 后端的unit测试

测试报告生成:使用nyc库
安装方式:
npm install nyc -D

package.json

"server-test": "mocha test/server --recursive --exit"

"coverage": "nyc --reporter=lcov --reporter=text --report-dir=coverage-server npm run server-test”

"nyc": {

  "check-coverage": true,

  "per-file": true,

  "lines": 90,

  "statements": 90,

  "functions": 60,

  "branches": 70

}

react前端测试

使用jest自带测试报告,配置如下:

"client-test": "jest”

"jest": {

  "automock": false,

  "setupTestFrameworkScriptFile": "./setupJest.js",

  "modulePaths": [

    "/shared/vendor/modules"

  ],

  "moduleNameMapper": {

    "^.+\\.(css|scss)$": "identity-obj-proxy"

  },

  "moduleFileExtensions": [

    "js",

    "jsx"

  ],

  "collectCoverage": true,

  "coverageReporters": [

    "json",

    "lcov",

    "text"

  ],

  "coverageDirectory": "coverage-client",

  "collectCoverageFrom": [

    "src/client/*/*.{js,jsx}"

  ],

  "coverageThreshold": {

    "global": {

      "branches": 80,

      "functions": 60,

      "lines": 80,

      "statements": 80

    }

  }

},

你可能感兴趣的:(测试报告如何添加)