【问题标题】:NG Test show names in consoleNG 测试在控制台中显示名称
【发布时间】:2018-12-31 11:56:36
【问题描述】:

当存在相当普遍的错误(是的源映射为假)时,很难识别失败的测试,如果我们可以显示测试名称而不是“executed 27 of 172”,这将有很大帮助

类似于“执行 27 (TextActivityService 测试) of 172

我在这里指的是所有测试都通过但控制台报告错误的时间。

这可能吗?

【问题讨论】:

  • 你不只是喜欢那些投反对票但还不足以添加评论的人......这是一个完全合理的问题,如果你遇到过这种情况,你会明白的为什么
  • 多年后我处于这种情况。有人对此有解决方案吗?像日志一样显示已执行的规范文件。如果出现错误,这确实是一个问题。

标签: angular angular-cli karma-runner


【解决方案1】:

您需要使用Karma Spec Reporter

用法:

  1. 要在您自己的 Node.js 项目中使用,只需执行

npm install karma-spec-reporter --save-dev

  1. 然后在karma.conf.js 中向记者添加“规格”

// karma.conf.js

...
  config.set({
  ...
    reporters: ["spec"],
    specReporter: {
      maxLogLines: 5,         // limit number of lines logged per test
      suppressErrorSummary: true,  // do not print error summary
      suppressFailed: false,  // do not print information about failed tests
      suppressPassed: false,  // do not print information about passed tests
      suppressSkipped: true,  // do not print information about skipped tests
      showSpecTiming: false // print the time elapsed for each spec
    },
    plugins: ["karma-spec-reporter"],
  ...

【讨论】:

  • 这种方法对我有用,不是我想要的,但现在 cli 中肯定有更多信息
  • 这个解决方案非常适合我。我想我现在会在任何地方使用它。
【解决方案2】:

当某些单元测试失败时,它会显示describeit 消息作为测试用例名称。

例如:

describe('TestComponent', () => {
  it('should pass test', () => {
    expect(false).toBeTruthy();
  });
});

那么,上述失败的单元测试将显示为TestComponent should pass test FAILED
Expected false to be truthy
在控制台中。

【讨论】:

  • 我的意思是当测试通过但在控制台中抛出错误时
  • @72GM 在这种情况下,最好在单元测试开始时添加console.log("TextActivityService Test")。基本上,将测试名称放在控制台日志中。
  • 这就是我要避免的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-12
  • 1970-01-01
  • 1970-01-01
  • 2015-08-13
  • 2011-09-05
  • 2011-04-27
  • 1970-01-01
相关资源
最近更新 更多