使用 Resharper 测试运行程序时如何在 qunit 测试中设置断点

发布于 2024-12-20 17:35:01 字数 172 浏览 8 评论 0原文

使用 Resharper 6 可以编写 qunit 测试并使用集成的 resharper 测试运行器运行这些测试,这是一件很棒的事情。但是,我想知道是否可以在测试和被测代码中设置断点。问题是,每次打开浏览器时,它都会使用不同的随机端口号,这意味着您不能仅在浏览器中设置断点并通过按 F5 重新运行测试。所以我想知道,这是否有可能?

It's a great thing that with Resharper 6 one can write qunit tests and run those with the integrated resharper test runner. However, I wonder if it is possible to set breakpoints in the tests and the code under test. The problem is, each time it opens the browser it uses a different randomized port number which means you can not just set breakpoints in the browser and rerun the tests by hitting F5. So I wonder, is it even possible somehow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与酒说心事 2024-12-27 17:35:01

使用 Resharper 和 Visual studio 的更简单方法。

只需将其作为 js 文件中的第一行:

QUnit.moduleDone = function(){}

Resharper 测试将不会完成,您可以在浏览器中刷新页面任意多次。然后您可以设置一个断点,然后在浏览器中按 F5 重新运行测试。

示例:

在页面的最顶部,您应该有:

  • 您的引用首先
  • QUnit.moduleDone = function() {};

像这样:

/// <reference path="Scripts/jquery-ver**.min.js"/>
/// <reference path="Scripts/jquery-ui.min.js"/>
/// <reference path="your_test_file.js"/>

QUnit.moduleDone = function() {};

这完美地工作!)

在您的浏览器中 - 只需按 F12(打开调试器窗口),设置断点并使用 F5 刷新页面))

An easier approach using Resharper and Visual studio.

Just put as your first line in the js file:

QUnit.moduleDone = function(){}

The Resharper test won't finish and you can refresh your page in browser as many times you want. You may put a breakpoint then and rerun the test by hitting F5 in browser.

Example:

At the very top of your page you should have:

  • your references first
  • QUnit.moduleDone = function() {};

like so:

/// <reference path="Scripts/jquery-ver**.min.js"/>
/// <reference path="Scripts/jquery-ui.min.js"/>
/// <reference path="your_test_file.js"/>

QUnit.moduleDone = function() {};

This works perfectly!)

In your browser - just hit F12 (open debugger window), set your breakpoints and refresh the page with F5))

爱她像谁 2024-12-27 17:35:01

不幸的是,目前还不可能 - 请参阅此请求。如果您需要调试,我建议您现在要做的就是规范地使用 QUnit - 创建一个 HTML 页面,将 JS 库、测试和 QUnit 放入其中,然后放入 QUnit HTML 元素以显示结果。这样,您就可以在 JS 中设置断点。

Unfortunately, it is not possible at the moment - see this request. What I suggest you do right now if you need debugging is to use QUnit canonically - create an HTML page, drop your JS libs, tests and QUnit into them, and put in the QUnit HTML elements to display the results. This way, you'll be able to set breakpoints in JS.

暗地喜欢 2024-12-27 17:35:01

如果您使用带有 Firebug 插件的 Firefox,您可以执行以下操作: 在您想要中断的代码中添加一条调试器语句:

var x = 2;
debugger;
...

将 Firebug 选项“对所有网页均有效”设置为 true。在 ReSharper 选项中,测试 > JavaScript 将 Firefox 设置为要使用的浏览器(如果它还不是您的默认浏览器)。

现在 Firebug 调试器将在调试器语句处中断。

PS 我用 Chrome 尝试过这个,但无法让它崩溃。有人知道该怎么做吗?

If you are using Firefox with the Firebug plugin, you can do this: add a debugger statement to your code where you want to break:

var x = 2;
debugger;
...

Set the Firebug option 'Active for all Web Pages' to true. In ReSharper options, Testing>JavaScript set Firefox as the browser to use (if it is not already your default).

Now Firebug debugger will break at the debugger statement.

PS I tried this with Chrome but couldn't get it to break. Anyone know how to do it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文