【问题标题】:how to do stop jasmine unit testing if any one of the test is failed如果任何一项测试失败,如何停止 jasmine 单元测试
【发布时间】:2018-07-19 22:04:00
【问题描述】:

我写了 500 多个单元测试方法。当我发出ng test 命令时。它开始测试所有 500 种方法。

如果任何测试用例失败,它不会停止并继续执行所有方法。所以我需要等待更多时间再次重新运行单元测试。

我知道我们可以通过执行ctr+c 来存在,然后再次使用ng test 命令重新运行单元测试。这种方式也花费了太多时间。

如果任何一个测试失败,是否可以停止(不存在)单元测试?

【问题讨论】:

标签: angular unit-testing typescript jasmine command


【解决方案1】:

如果您想从所有测试用例中排除该文件。尝试在 cli 配置文件中添加 exclude 部分。

src/tsconfig.app.json: 

此处显示:

{
  "compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2016",
      "dom"
    ],
    "outDir": "../out-tsc/app",
    "target": "es5",
    "module": "es2015",
    "baseUrl": "",
    "types": []
  },
  "exclude": [
    "test.ts",
    "filename.spec.ts"
  ]
}

【讨论】:

    【解决方案2】:

    另一种方法是在jasmine 库中使用fdescribe。它与 jasmine describe 函数完全相同,只是通过使用此函数 karma(如果您使用 karma)仅执行 fdescribe 块并忽略所有 describe 块,例如:

    fdescribe('this block will executed' , async()=>{ 
     ....
     it('only this method will during tests', ()=>{
        expect(1).toEqual(1);
     });
    ...
    describe('this block not executed' ()=>{
       .....
    }
    

    测试完成后,您可以简单地将 fdescribe 函数替换为 describe

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      相关资源
      最近更新 更多