I am wondering is there any alternative lib to the shim feature provided in Microsoft fake framework since it is only supported in ultimate version?
-
Fakes are also available in Visual Studio 2012 Premium edition starting with Update 2. – Oleg Sych Oct 01 '13 at 22:53
-
I've heard TypeMock Isolator has similar functions, but it's fairly expensive too. – Magus Oct 30 '13 at 16:21
-
@sunquiang.leo Have you been able to find anything? – zaitsman Dec 29 '14 at 05:37
3 Answers
Prig hasn't been updated to work with VS 2017, but Pose does, and works really well for what I needed it for (basic shimming of Environment.UserName
, and DateTime.Now
and similar), and has a really nice interface:
// Create shims. They only apply within this isolate block.
var dateTimeShim = Shim.Replace(() => DateTime.Now)
.With(() => new DateTime(2010, 1, 1));
var usernameShim = Shim.Replace(() => Environment.UserName)
.With(() => "john.wick");
// Shims are only active within an Isolate block - and you
// have to pass all shims you want to be active.
PoseContext.Isolate(() =>
{
// Run your test - shims are active at this point.
RunTest();
}, dateTimeShim, usernameShim);
EDIT
I should note that I get lots of errors when doing fairly basic tests - really scary errors like "Common Language Runtime detected an invalid program.", and "JIT Compiler encountered an internal limitation." so caveat emptor.

- 13,221
- 9
- 64
- 84

- 36,301
- 12
- 91
- 131
-
Would you happen to know if it's still being maintained and working well with more recent runtimes such as .NET Core 3 and .NET 4.8? – Crono Oct 02 '19 at 14:19
There are three frameworks to my knowledge that allow you to mock non virtual methods and sealed classes like Fakes' Shims. There are
They are all commercial because they use the Profiling API, which is very hairy and poorly documented, so coding them is a real pain.
And for the record I'm all for fakes. Most code that people are working on is legacy code. One of the Pragmatic Programmer's rules of refactoring is make sure that you have unit test coverage before any refactorings to avoid regression. This makes Fakes and similar frameworks super useful, especially when the legacy code was not written for test-ability.

- 14,998
- 7
- 42
- 68

- 402
- 4
- 9
An open source alternative is Prig. MIT licenced and still active - but slightly behind with VS IDE

- 552
- 3
- 17