Unit Testing Improvements in ReSharper 7

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.)

This entry was posted in ReSharper Tips&Tricks and tagged , , , . Bookmark the permalink.

24 Responses to Unit Testing Improvements in ReSharper 7

  1. Olaf says:

    If resharper knows the method specified by the TestCaseSource doesn’t exist, is it then possible to create the missing method from a contextmenu?

  2. Entropy says:

    Javascript tests impossible to use. They not run correctrly or never stops.

  3. Joe White says:

    @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?

  4. @Joe Thanks, this is so true )
    @Entropy Absolutely concur with @Joe, there’s no way we can investigate your problem without further details.

  5. Nathan says:

    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.

  6. Nathan says:

    FYI, I’m using released Resharper 7, QUnit, in browser.

  7. Victor Kropp says:

    @Olaf, I filed this suggestion in our tracker: http://youtrack.jetbrains.com/issue/RSRP-328851
    Thanks!

  8. Victor Kropp says:

    @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.

  9. Thomas Deutsch says:

    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?

  10. Danil Flores says:

    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:

    ///

  11. Danil Flores says:

    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:
    ///

  12. fschwiet says:

    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

  13. Dmitri Nesteruk says:

    @fschwiet: this link points to the latest reference on test framework support, though the two are likely to have identical content.

  14. fschwiet says:

    Thank you Dmitri

  15. typeasec says:

    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?

  16. Victor Kropp says:

    Unfortunately TypeScript is not yet supported. When it will be fully supported by ReSharper, it will include support for Unit Testing Frameworks as well.

  17. Adam says:

    Is debugging JS tests using PhantomJS supported?

  18. Victor Kropp says:

    It is not yet supported. Please vote & watch corresponding request http://youtrack.jetbrains.com/issue/RSRP-330187

  19. Jim Speaker says:

    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.

  20. Lee says:

    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

  21. Alexander Kurakin says:

    @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!

  22. Alexander Kurakin says:

    /// <reference path=”path/to/qunit-1.11.0.js” />

  23. Petr Diviš says:

    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

  24. Alexander Kurakin says:

    @Petr, I filled a new ticket to YouTrack http://youtrack.jetbrains.com/issue/RSRP-383744. You are welcome to track its status.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>