【问题标题】:Stack trace for Jasmine test with the Resharper 7 test runner使用 Resharper 7 测试运行器进行 Jasmine 测试的堆栈跟踪
【发布时间】:2012-06-28 12:47:41
【问题描述】:

如何让 Resharper 7 测试运行程序显示 Jasmine 测试的堆栈跟踪。

我的设置是 Resharper 7(内置 Jasmine)测试运行程序和 PhantomJs。执行任何失败的测试时,错误消息总是以:

Exception doesn't have a stacktrace

Phantom 在 1.6 “Lavender” 版本中添加了在发生错误时打印堆栈跟踪的功能。

要复制它,只需创建一个 mytest.js 文件并向其中添加以下代码:

describe("A suite", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(false);
  });
});

【问题讨论】:

标签: unit-testing resharper jasmine


【解决方案1】:

抱歉,我没有使用 Resharper,但我曾经在使用 phantomjs 和 jasmine ConsoleReporter 时遇到过同样的问题。

我认为这归结为这样一个事实,即 jasmine 不会因预期失败而抛出错误消息,并且只有在实际抛出错误时(jasmine.js)才会由 phantomjs 捕获堆栈:

jasmine.ExpectationResult = function(params) {
...
var trace = (params.trace || new Error(this.message));
};

如下更改该行为我修复了它:

var err;
try { throw new Error(this.message); } catch(e) { err = e };
var trace = (params.trace || err);

【讨论】:

    【解决方案2】:

    在您拥有 javascript (jasmine) 单元测试的规范文件中,您需要引用正在测试的源代码。 通常你在 SpecRunner.html 中有这个,但 Resharper 会滚动它自己的 SpecRunner。

    将此 reference 行添加到 XyzSpec.js 文件的顶部

    /// <reference path="/js/path-goes-here/your-file-here.js" />
    
    describe("Utils", function () {
        describe("when calculating quantity", function() {
    ...
    

    在我开始在 Resharper 的规范运行器中四处寻找之前,我几乎要发疯了。

    PS:如果出现新问题“Unit Test Runner failed to load test assembly”并且您将 Chrome 作为默认浏览器,请在 Resharper 选项中更改 javascript 单元测试的浏览器。

    【讨论】:

    • 我已经引用了我的 javascript 文件。如果我不添加它,我的测试就会失败。不幸的是,仍然没有堆栈跟踪,但我告诉了 R# 团队,他们计划在 7.1 版本中使用它
    【解决方案3】:

    当我记录问题时,Jetbrains Resharper 团队给出了很好的回应。他们修复了它,它在 Resharper 的 7.1 版本中,可以从他们的 EAP site 下载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多