Showing posts with label ReSharper. Show all posts
Showing posts with label ReSharper. Show all posts

Tuesday, November 24, 2020

Enable ReSharper unit tests runner with TypeMock isolator

If you use TypeMock isolator for writing unit tests (which is great library for mocking from my point of view) and ReSharper to make user experience in Visual Studio better (which is another great tool :) ) then you may face with the following problem when try to run unit tests in ReSharper test runner: tests will fail with the following error

TypeMock.TypeMockException :
*** Typemock Isolator is currently disabled. Enable using the following:

* Within Visual Studio:
    - Use Typemock Smart Runner 
    - For other runners, Choose Typemock Menu and click "Integrate with Other Runners"
 
  * To run Typemock Isolator as part of an automated process you can:
     - run tests via TMockRunner.exe command line tool
     - use 'TypeMockStart' tasks for MSBuild or NAnt
 
For more information consult the documentation (see 'Running Unit Tests in an Automated Build')
    at TypeMock.InterceptorsWrapper.VerifyInterceptorsIsLoaded()

This error will be still there even if “Integrate with other runners” option will be checked in Typemock menu:

In order to fix this problem do the following:

1. Go to TypeMock installation folder (C:\Program Files (x86)\Typemock\Isolator\x.x) and create or edit knownRunners.dat file there (you may also try to put it to C:\Program Files (x86)\Typemock\Isolator\x.x\BuildScripts\AutoDeploy folder).

2. In this file add process name of ReSharper unit tests runner on separate line: for ReSharper 2020 it will be “ReSharperTestRunner64c.exe” (for ReSharper 2021 "ReSharperTestRunner.exe").
In order to know process name of the runner - run unit tests with it, find it in Process Explorer (if runner was ran from Visual Studio it will be shown under Visual Studio process tree) > right click > Properties > copy exe file name.

After that run unit tests with TypeMock in ReSharper test runner – they should work now.

Monday, June 29, 2020

Problem with ReSharper unit test runner with NUnit 3.12: unit test is inconclusive

Some time ago we switched to NUnit 3.12 and NUnit3TestAdapter in Camlex library and noticed the following problem with ReSharper unit test runner: all unit tests were marked as “inconclusive” and didn’t run. At the same time built-in Visual Studio test runner worked. I used 2019 version of ReSharper when found this problem.

By searching the web I found similar problems from other people in JetBrains support site. In order to fix it I uninstalled 2019 version and installed latest available version of ReSharper JetBrains.ReSharperUltimate.2020.1.3. After that test become working again:

So if you will face with the same problem try to install last ReSharper version.

Thursday, June 17, 2010

ReSharper live template for Sharepoint utilities

In everyday Sharepoint development we often need to create many console utilities for various maintenance tasks which should be performed on production or staging environments (e.g. install bugfix on living Sharepoint site, trace some information from production site, etc). Before to run program on remote server we test it on our development environment and then copy it to remote server and run it there with different site URL (in most cases there are different URLs on production and dev environment). So we have to write the following code each time we need to create such utility:

   1: class Program
   2: {
   3:     static void Main(string[] args)
   4:     {
   5:         if (args.Length != 1)
   6:         {
   7:             Console.WriteLine("Usage: exe <site_collection_url>");
   8:             return;
   9:         }
  10:  
  11:         using (var site = new SPSite(args[0]))
  12:         {
  13:             using (var web = site.OpenWeb())
  14:             {
  15:                 // code goes here
  16:             }
  17:         }
  18:  
  19:     }
  20: }

It is very annoying. So I created ReSharper live template which slightly simplify this task. Just add the following code to User Template (in Visual Studio menu ReSharper > Live Templates > User Templates > New Template):

   1: if (args.Length != 1)
   2: {
   3:     Console.WriteLine("Usage: exe <site_collection_url>");
   4:     return;
   5: }
   6:  
   7: using (var site = new SPSite($site$))
   8: {
   9:     using (var web = site.OpenWeb($web$))
  10:     {
  11:     }
  12: }

and specify “Shortcut” for it (e.g. “spsite”). Now you are able to create the above code by typing “spsite”. ReSharper will offer spsite template for you (like it does for “for” or “foreach” templates):

image

After selecting of “spsite” template ReSharper will add this code for you and it will allow to specify parameters in SPSite() constructor and OpenWeb() method by clicking Enter key (which is more convenient in comparison with VS code snippets):

image

This is a little automation which slightly simplifies creation of console utilities for Sharepoint.