The ReSharper unit test runner has become an indispensable part of ReSharper. The ability to run and debug tests from a location in code, together with an integrated unit test runner make testing with ReSharper a streamlined and pleasant experience, and a rich variety of plug-ins supporting many popular unit test frameworks makes ReSharper relevant whatever unit testing framework you choose.
Here is an overview of some of the new unit testing features that we are shipping in ReSharper 7.
Jasmine Support
The previous version of ReSharper has shipped with support for the QUnit JavaScript test framework. In this release, we have added support for Jasmine — a behavior-driven development framework for testing JavaScript code:
Naturally, just like any other type of unit tests, Jasmine tests are presented in the ReSharper unit test runner:
PhantomJS Test Runner
In addition to being able to run QUnit and Jasmine tests in a browser, ReSharper 7 offers an alternative mechanism: one can use PhantomJS – a command-line interface to WebKit – to run JavaScript unit tests instead. To start using it, download and unpack PhantomJS, then open up ReSharper options (the Unit Testing|JavaScript Tests tab) and specify the install location:
Now, any all JavaScript tests will be executed in a PhantomJS environment. Since a full browser is not needed for the tests, ReSharper will not open up a summary page inside a web browser.
NUnit Improvements
The new version of ReSharper comes with support for the TestCaseSource
attribute. This attribute lets test authors define external variables that store test data. For example:
Since the argument to the attribute references a variable by name, ReSharper comes with appropriate inspections…
…as well as code completion:
As of this release, ReSharper supports NUnit version 2.6 by default.
Support for Other Frameworks
If you are looking for a test framework that isn’t supported by ReSharper out of the box, don’t worry – many plugin authors have already prepared the corresponding ReSharper plug-ins. Frameworks supported by ReSharper plugins today include AgUnit, Gallio/MbUnit, MSpec, and XUnit.
That’s it — happy coding! (And testing, of course.)
If resharper knows the method specified by the TestCaseSource doesn’t exist, is it then possible to create the missing method from a contextmenu?
Javascript tests impossible to use. They not run correctrly or never stops.
@Entropy, you’re going to have to give more information than that. What do your tests look like? Which framework are you using (QUnit, Jasmine, or something else through a third-party plug-in)? Are you running the tests in the browser, or using Phantom? Are you using the released version of ReSharper 7, or one of the EAP and/or beta builds?
@Joe Thanks, this is so true )
@Entropy Absolutely concur with @Joe, there’s no way we can investigate your problem without further details.
The Javascript Unit Tests seem impossible to use for me too. Any unit test file will be testing another script – but how do you specify that? Also, it will most likely need to have other dependent scripts, or even a DOM to do UI unit tests – yet there is no configuration available for this from what I can see. Also, tests inlined in .html files are not detected either. I’m excited about this feature, if it can do what I need it too.
FYI, I’m using released Resharper 7, QUnit, in browser.
@Olaf, I filed this suggestion in our tracker: http://youtrack.jetbrains.com/issue/RSRP-328851
Thanks!
@Nathan, you should tell ReSharper about source code dependencies using
/// <reference path="/path/to/code.js" />
doc comment somewhere inside file with tests.
Unfortunately it’s not yet possible to provide DOM to test against, there is a related request in our tracker: http://youtrack.jetbrains.com/issue/RSRP-274956 Please, vote!
Tests detection in html is disabled until the aforementioned request is implemented.
I want to test my node.js code.
But there is a problem. I want to run the Jasmine Tests in my node.js environment.
This seems to be impossible, because i need a website-Project to run my tests in. But Resharper can not find my tests on a Website Project.
Is there a workaround?
The main problem with both the QUnit and Jasmine test runners in Resharper is that it expects that the JS source (system under test) and the JS tests are in the same folder structure, which is not the case for most production-ready systems. Is there any way to specify where these files should be pulled from? Perhaps as a config file somewhere?
It would be great to specify something like this in a JS config file
And then reference them like this:
///
Whoops, last comment didn’t process correctly. Reposting:
The main problem with both the QUnit and Jasmine test runners in Resharper is that it expects that the JS source (system under test) and the JS tests are in the same folder structure, which is not the case for most production-ready systems. Is there any way to specify where these files should be pulled from? Perhaps as a config file somewhere?
It would be great to specify something like this in a JS config file
And then reference them like this:
///
It’d be nice if you also included links to documentation on writing custom test runners for Resharper. Are these the latest still? http://confluence.jetbrains.net/display/ReSharper/Test+Framework+Support
@fschwiet: this link points to the latest reference on test framework support, though the two are likely to have identical content.
Thank you Dmitri
Am trying to get unit tests running using ReSharper 7.1/VS2012/QUnit and TypeScript 0.8.1 but so far w/o luck prior building the Javascript and manually adding the reference to the tested JS.
Is ReSharper supposed to run with TypeScript in the above combination?
How to get rid of the manual inclusion of the reference to the JS post build if it is?
Unfortunately TypeScript is not yet supported. When it will be fully supported by ReSharper, it will include support for Unit Testing Frameworks as well.
Is debugging JS tests using PhantomJS supported?
It is not yet supported. Please vote & watch corresponding request http://youtrack.jetbrains.com/issue/RSRP-330187
Dan Flores question above is right on.
I’m not seeing a way to specify that the tests should not run using the dynamic ports on the development server. The tests, when simply run in a browser (specrunner.html) can reference source js files via relative path allowing a separate project folder for jasmine tests to be used. This of course is appropriate for enterprise dev.
Running phantomjs or browsers via Resharper7/VS seems to have me locked to dynamic ports and dev server.
Is there config or options I’m missing? Or, is this just written such that the test js really does have to live along-side production code?
Thanks in advance.
Is there a way to update the version of qunit in Resharper (>7)?
I’m getting errors running some tests and would like to use the latest version of qunit.
Thanks
Lee
@Lee, you may try out to add the following reference to the top of your js file with tests:
/// .
In this case, ReSharper will use this qUnit version to run the tests. However, please note if there are any API changes in this qUnit version, there is a chance ReSharper won’t support it.
Please let us know about the results.
Thanks!
/// <reference path=”path/to/qunit-1.11.0.js” />
When I run unit tests with jasmine, PhantomJS stops responing, while in Chrome the unit tests run without problems.
I use: VS 2010SP1, Resharper 8, PhantomJS 1.9.1.0, Jasmine 1.2rc1, angular 1.1.5, angular-mocks 1.0.6
https://gist.github.com/czechdude/6316616
@Petr, I filled a new ticket to YouTrack http://youtrack.jetbrains.com/issue/RSRP-383744. You are welcome to track its status.