Error trying to run nunit tests using TypeMock in LINQPad

I love LINQPad and use it daily. I tried to find a way to create and run ad-hoc tests with nunit and TypeMock in LINQPad for a while.

So, I came across and got some results, but some links are still missing.

Here is what I did:

At this point, I can get Nunit and Typemock to work with some manual step (you need to copy the dll nunit and typemock files to the executable directory, for example, \ AppData \ Local \ Temp \ 1 \ LINQPad \ skbidgcw).

But if I add my assemblies (which I want to test) in the LINQPad script, the test will fail because NUnit cannot find the assemblies in the executable directory. I even tried copying all the DLLs to this, but this will also fail due to:

System.IO.FileNotFoundException : Could not load file or assembly 'LINQPad, Version=1.0.0.0, Culture=neutral, PublicKeyToken=21353812cd2a2db5' or one of its dependencies. The system cannot find the file specified.

My linqpad request is here: http://pastebin.com/QtPNCv25

Any help would really be appreciated!

As a side note, I also tried using NUnitLite , while it performs Nunit tests perfectly, I can’t find a way to get it to work with Typemock, it gives the error message “Typemock Isolator is required to communicate with the Coverage Tool to run”.

+4
source share
1 answer

Finally found a way to do what I wanted using NUnitLite.

  • The following environment variables have been added for my system to enable the Typemock profiler.

Cor_Enable_Profiling = 0 × 1

COR_PROFILER = {B146457E-9AED-4624-B1E5-968D274416EC}

(NUnitLite may have run the test in another AppDomain, so setting environment variables through LINQPad did not include the profiler, this can be bypassed if there is a switch in NUnitLite, but I did not investigate.)

  • Place TypeMock.dll and Typemock.ArrangeActAssert.dll in the Linqpad plugins folder.

  • Create a new query and add NUnitLite via Nuget. Add the required namespaces.

Now the following should work.

 void Main() { new NUnitLite.Runner.TextUI().Execute( new[]{"-noheader"} ); } // Define other methods and classes here [Test, Isolated] public void TestMock() { Isolate.WhenCalled( () => DateTime.Now ).WillReturn( DateTime.Today ); var dt = DateTime.Now; Assert.AreEqual( DateTime.Today, dt ); } 

Now my life should be much easier. Thanks!

+1
source

Source: https://habr.com/ru/post/1443879/


All Articles