Reputation: 61
I love LINQPad and use it daily. I have been trying to find a way to create and run ad-hoc tests with nunit and TypeMock in LINQPad for a while.
So I stumbled around and got some results, but some links are still missing.
Here's what I have done:
Create a new query in linqpad, add reference to NUnit and Typemock assemblies.
Create an Nunit runner. (Thanks to http://www.paraesthesia.com/archive/2008/02/21/template-for-quick-typemock-testing.aspx)
Add a couple of environment variables to enable Typemock profiler.
At this point, I am able to get Nunit and Typemock to work with some manual step (need to copy nunit and typemock dlls to the executing directory, e.g., \AppData\Local\Temp\1\LINQPad\skbidgcw).
But if I add our assemblies (which I want to test) to the LINQPad script, the test would fail, due to NUnit unable to find the assemblies in the executing directory. I even tried copying all the DLLs to that, but this would 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 query is here: http://pastebin.com/QtPNCv25
Any help will really be appreciated!
As a side note, I also tried using NUnitLite, while it runs Nunit tests beautifully, I can't find a way to make it work with Typemock, it throws error saying "Typemock Isolator needs to be linked with Coverage Tool to run".
Upvotes: 4
Views: 571
Reputation: 61
Finally found a way to do what I wanted using NUnitLite.
Cor_Enable_Profiling=0×1
COR_PROFILER={B146457E-9AED-4624-B1E5-968D274416EC}
(NUnitLite may have been running the test in another AppDomain, and so setting the environment variables through LINQPad did not enable the profiler; this may be circumvented if there's a switch to do so in NUnitLite, but I haven't researched.)
Put TypeMock.dll and Typemock.ArrangeActAssert.dll in Linqpad's plugins folder.
Create new query and add NUnitLite through Nuget. Add necessary 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 considerably easier. Thanks!
Upvotes: 2