Unit Testing Improvements in ReSharper 7
July 27th, 2012 by Dmitri NesterukThe 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.)
Tags: NUnit, ReSharper, ReSharper 7, unit testing

July 27th, 2012 at 6:02 pm
If resharper knows the method specified by the TestCaseSource doesn’t exist, is it then possible to create the missing method from a contextmenu?
July 29th, 2012 at 10:09 am
Javascript tests impossible to use. They not run correctrly or never stops.
July 30th, 2012 at 1:08 am
@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?
July 30th, 2012 at 5:53 pm
@Joe Thanks, this is so true )
@Entropy Absolutely concur with @Joe, there’s no way we can investigate your problem without further details.
August 1st, 2012 at 6:14 am
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.
August 1st, 2012 at 6:16 am
FYI, I’m using released Resharper 7, QUnit, in browser.
August 1st, 2012 at 3:45 pm
@Olaf, I filed this suggestion in our tracker: http://youtrack.jetbrains.com/issue/RSRP-328851
Thanks!
August 1st, 2012 at 3:57 pm
@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.
August 4th, 2012 at 2:43 am
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?
August 29th, 2012 at 10:49 pm
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:
///
August 29th, 2012 at 10:50 pm
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:
///
September 17th, 2012 at 1:28 am
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
September 17th, 2012 at 12:02 pm
@fschwiet: this link points to the latest reference on test framework support, though the two are likely to have identical content.
October 11th, 2012 at 7:48 am
Thank you Dmitri
November 21st, 2012 at 5:54 pm
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?
November 21st, 2012 at 6:44 pm
Unfortunately TypeScript is not yet supported. When it will be fully supported by ReSharper, it will include support for Unit Testing Frameworks as well.
November 23rd, 2012 at 6:02 pm
Is debugging JS tests using PhantomJS supported?
November 23rd, 2012 at 6:30 pm
It is not yet supported. Please vote & watch corresponding request http://youtrack.jetbrains.com/issue/RSRP-330187
January 17th, 2013 at 4:59 am
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.