使用 Resharper 测试运行程序时如何在 qunit 测试中设置断点
使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Resharper 和 Visual studio 的更简单方法。
只需将其作为 js 文件中的第一行:
QUnit.moduleDone = function(){}
Resharper 测试将不会完成,您可以在浏览器中刷新页面任意多次。然后您可以设置一个断点,然后在浏览器中按 F5 重新运行测试。
示例:
在页面的最顶部,您应该有:
像这样:
这完美地工作!)
在您的浏览器中 - 只需按 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:
like so:
This works perfectly!)
In your browser - just hit F12 (open debugger window), set your breakpoints and refresh the page with F5))
不幸的是,目前还不可能 - 请参阅此请求。如果您需要调试,我建议您现在要做的就是规范地使用 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.
如果您使用带有 Firebug 插件的 Firefox,您可以执行以下操作: 在您想要中断的代码中添加一条调试器语句:
将 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:
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?