简体   繁体   English

在Visual Studio中运行JavaScript单元测试

[英]Run JavaScript unit tests inside of Visual Studio

I have been searching for a good way to run JavaScript unit tests inside of the Visual Studio IDE. 我一直在寻找在Visual Studio IDE中运行JavaScript单元测试的好方法。 I currently use TestDriven.net to run my C# units tests and it is very convenient to be able to quickly get the result of my tests in the output pane. 我目前使用TestDriven.net来运行我的C#单元测试,能够在输出窗格中快速获取测试结果非常方便。 I would love to find a similar experience for JavaScript (ideally working with TestDriven.net). 我很想找到类似的JavaScript体验(理想情况下与TestDriven.net合作)。

I have read about different solutions that let you execute JavaScrpt unit tests. 我已经阅读了有关允许您执行JavaScrpt单元测试的不同解决方案。 Some have their own JS engine while others like JS-Test-Driver are able to send the code to the browsers and fetch the results. 有些拥有自己的JS引擎,而其他像JS-Test-Driver则能够将代码发送到浏览器并获取结果。 But I have yet to see something that is integrated into VS. 但我还没有看到融入VS的东西。

Does anyone know of an extension that might do this? 有谁知道可能会这样做的扩展?

After nine months there are now a couple answers to this question. 九个月后,这个问题现在有几个答案。

I created an open source project called Chutzpah - A JavaScript Test Runner . 创建了一个名为Chutzpah的开源项目- 一个JavaScript Test Runner Chutzpah enables you to run JavaScript unit tests from the command line and from inside of Visual Studio. Chutzpah使您可以从命令行和Visual Studio内部运行JavaScript单元测试。 It also supports running in the TeamCity continuous integration server. 它还支持在TeamCity持续集成服务器中运行。

Another solution is part of the next version of Resharper. 另一个解决方案是下一版Resharper的一部分。 In Resharper 6 there is an integrated QUnit test runner . 在Resharper 6中有一个集成的QUnit测试运行器

It is possible to use JsTestDriver to be a test-runner in Visual Studio. 可以使用JsTestDriver成为Visual Studio中的测试运行器。 Once a server has been started, with browsers attached, one can run tests directly from within Visual Studio. 启动服务器后,如果连接了浏览器,则可以直接从Visual Studio中运行测试。

The Console-window will then give the output of the test results. 然后,Console窗口将提供测试结果的输出。 I won't go to implementation details here, but the following how-to should be enough to get you started on the actual setup of Visual Studio / JsTestRunner. 我不会在这里讨论实现细节,但是下面的操作方法应该足以让您开始实际设置Visual Studio / JsTestRunner。

Console output from chrome and internet explorer (ignore my bad test-names): chrome和Internet Explorer的控制台输出(忽略我的错误测试名称): Chrome和Internet Explorer的控制台输出

JsTestDriver is mainly a test-running tool to verify multiple browsers. JsTestDriver主要是一个用于验证多个浏览器的测试运行工具。 To get good unit-tests on the javascript itself, one can plug in other test-specific tools like JasmineBDD ( jasmine to jstestdriver adapter ). 要在javascript本身上获得良好的单元测试,可以插入其他特定于测试的工具,如JasmineBDDjasmine到jstestdriver适配器 )。

JsTestDriver also opens up for the possibility to test against multiple browsers as a build step on your continuous integration server ie: Hudson ( Continuous Integration with Hudson and jstestdriver ). JsTestDriver还打开了可以测试多个浏览器作为持续集成服务器上的构建步骤的可能性,即:Hudson( 与Hudson和jstestdriver的持续集成 )。 This then allows a dev to test against a certain browser or two while developing locally, but then verify the result against any range of OS / browser combinations on the build server. 然后,这允许开发人员在本地开发时针对某个或两个浏览器进行测试,然后针对构建服务器上的任何OS /浏览器组合范围验证结果。

Just found this article (and this question) when looking for the same thing. 在寻找同样的事情时,刚发现这篇文章(和这个问题)。

Integrating JavaScript Unit Tests with Visual Studio - Steven Walther 将JavaScript单元测试与Visual Studio集成 - Steven Walther

It does have a lot of work onto it, but it seems that it really brings a nice interaction. 它确实有很多工作,但它似乎真的带来了很好的互动。 For sure worth the hassle if you're working on a JavaScript heavy application. 如果您正在处理JavaScript繁重的应用程序,那肯定值得麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Visual Studio和Team City用单元AND集成测试测试javascript的正确方法是什么? - What is the correct way to test javascript with unit AND integrations tests, using Visual Studio and Team City? 在 Visual Studio Code 中运行 JavaScript - Run JavaScript in Visual Studio Code Node Tools Visual Studio(NTVS)中的调试单元测试 - Debugging unit tests in Node Tools Visual Studio (NTVS) 如何使用Visual Studio Code调试Angular 4单元测试 - How to debug a Angular 4 unit tests using Visual Studio Code 如何针对不同的依赖版本运行 javascript 单元测试? - How to run javascript unit tests against different dependency versions? 如何在Visual Studio Code中调试从Grunt运行的Jasmine测试? - How to debug Jasmine tests run from Grunt in Visual Studio Code? 如何使用 Jasmine 和 Visual Studio 代码运行特定测试? - How to run specific tests using Jasmine and Visual studio code? 使用 ”//?” 在 Visual Studio 代码中运行 javascript - using “//?” to run javascript in Visual Studio code 无法在 Visual Studio 代码中运行 javascript 代码 - unable to run javascript code in visual studio code 允许直接在Visual Studio中运行javascript代码 - allow to run javascript code right in visual studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM