如何使用Testacular(Karma)调试Jasmine规范运行? [英] How do I debug a Jasmine spec run with Testacular (Karma)?

查看:76
本文介绍了如何使用Testacular(Karma)调试Jasmine规范运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于Jasmine规范的小项目,我使用Testacular作为我的测试运行员。
我不明白我如何调试应用程序代码或规范代码。当我尝试在Chrome开发工具中设置断点时,下次运行规范时不会触发该断点,因为它每次都会使用新的查询字符串加载文件。

I have a small project with Jasmine specs and I am using Testacular as my test runner. I don't understand how I can debug, both the app code or the spec code. When I try to set a breakpoint in Chrome Dev Tools it isn't hit next time the specs run because it loads the files every time with a new query string.

到目前为止我发现的最好的事情是使用console.log(),但我宁愿使用Chrome Dev Tools断点。

The best thing I found so far is to use console.log() but I would rather use Chrome Dev Tools breakpoints.

(我使用Visual Studio 2012进行开发。)

(I am using Visual Studio 2012 for development.)

谢谢

推荐答案

Testacular不是最好用的工具调试。它的强大之处在于它将在多个浏览器中运行您的测试,并且可以非常快速地完成,并且每次更改文件时都可以执行此操作,因此它会告诉您是否已经破坏了测试。但是如果你需要调试,它不是最好的工具。

Testacular is not the best tool to use for debugging. It's power lies in the fact that it will run your tests in multiple browsers, and do it EXTREMELY quickly, and can do it every time you change a file, so therefore it will tell you if you have broken a test. But if you need to debug, it's not the best tool.

您确实可以在代码中添加调试器语句以使其中断,但是如果您在测试中遇到相同的断点,可能会达到数十次或更多次这是在多个测试中遇到的常见代码行。也许它只是在一个给定的场景中打破,所以你必须跳过所有断点,除了你遇到问题的那一个。如果您使用的是mocha或jasmine,则可以在整个测试套件中仅运行一次测试。随着jasmine将一个测试从it()更改为iit(),使用mocha就是it.only()。但即便如此,testacular仍然是这项工作的错误工具。

You can indeed put a "debugger" statement in your code to cause it to break, but you may end up hitting that same breakpoint dozens or more times in your tests if that is a common line of code that is hit in multiple tests. Where perhaps it's only breaking in one given scenario, so you have to skip all the breakpoints except the one occurrence where you are seeing a problem. If you are using mocha or jasmine there is a way to run only a single test in your entire test suite. With jasmine that's changing that one test from it() to iit(), with mocha it's it.only(). But even so, testacular still is the wrong tool for this job.

更好的解决方案是使用不同的测试设置并运行单个测试。使用jasmine或mocha或您选择的任何测试框架都可以轻松完成。您已经在其中一个框架中编写了测试版本,因为testacular是一个自动化工具而不是测试框架。所以只需创建一个测试运行器文件并使用它,加载文件,如果你正在使用chrome,进入开发工具,点击MAC上的Command-O或Windows上的Control-O,然后选择你想要的文件设置一个断点,然后设置断点,然后用气体烹饪。

A far better solution is to use a different test "setup" and just run the single test that's breaking. This is easily accomplished using jasmine or mocha or whatever your test framework of choice is. You will already be writing your testacular tests in one of those frameworks since testacular is an automation tool and not a test framework. So just create a test runner file and using that, load the file up, and if you're using chrome, go into the dev tools, hit Command-O on MAC or Control-O on windows, and select the file you wish to put a breakpoint in, and set your breakpoint, and you're cooking with gas.

使用传统的测试运行器和测试框架不会与使用冲突真是太过分了。这两个人会愉快地一起跑。

Using the traditional "test runner" with your test framework won't clash with using testacular at all. The two will run in concert happily.

这里是我在主要3个测试框架中做这个的首选文章的链接:

Here's links to my preferred articles for doing this in the major 3 test frameworks:

jasmine: http://net.tutsplus.com/tutorials / javascript-ajax / testing-your-javascript-with-jasmine /

QUnit:http://www.testdrivenjs.com/getting-started/qunit-setup/

摩卡:我没有关于这篇文章的链接。到2013年2月中旬,我的PluralSight,com测试客户端JavaScript的课程将会发布,你可以在那里找到它,以及有关设置QUnit和Jasmine的详细说明。他们有一个简短的免费试用版,您可以使用它来查看内容而无需付费。该URL将在发布时链接到该课程。 http://pluralsight.com/training/Au​​thors/Details/joe-eames

Mocha: I don't have a link to a good article for this. By the middle of February 2013 my PluralSight,com course on testing clientside JavaScript will be published and you can find it there, along with detailed directions on setting up QUnit and Jasmine. They have a short free trial that you can use to view the content without paying. This URL will link to that course when it gets published. http://pluralsight.com/training/Authors/Details/joe-eames

这篇关于如何使用Testacular(Karma)调试Jasmine规范运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆