Posted By: Peli de Halleux | Jan 29th @ 1:00 PM | 61,387 Views | 24 Comments
Nikolai Tillman, a member of the RiSE group at Microsoft Research, gives a short demo of Moles, a new framework that allows replacing any .NET method with a delegate. In the context of unit testing, one can use Moles to isolate from environment dependencies (such as time, file system, database, etc...) even when those dependencies are hard-coded through static method or sealed types. In this demo, Nikolai goes through the famous Y2K bug and how to test it...

The Research in Software Engineering team (RiSE) coordinates Microsoft's research in Software Engineering in Redmond, USA.

Rating:
9
0

Very cool! One question: Does Moles work with other test frameworks (NUnit, MbUnit, ...) or just with the Visual Studio testing framework.

 

Also where can I buy one of those whiteboards Tongue Out It looks to be an EduBoard interactive whiteboard P3000, but they don't appear to have any retailers in the US.

 

Keep up the great work!

Nice!  Now, if you could convince the C#/CLR guys to add this to the next release, so that the DLL generation was unnecessary...

 

In other words, I would like it if you could change the syntax of that added line of code to something like:

 

override get DateTime.Now =
        () => new DateTime(2000, 1, 1);

AdamSpeight2008
AdamSpeight2008
The Bandito Coder

Am I the only one where this seem wrong by calling this testing when you modify the code by inserting

 MDate.GetNow = () => New Date(2000,1,1)

 

Or am I missing something.

 

Idea add a attribute to the class,method etc, where within that scope the GET is intercepted and the test value is returned.

For Example:-

<Test.InterceptGet("System.Date.Now",() => new Date(2010,4,1))>

when we do testing we test a class at a time, so all external stuff is either stubbed or mocked so that you just test the functionality of the single class instead of doing system wide testing that are a nightmare to maintain. and if you test every single layer and it behaves as you expect while testing than everything should be good atleast from the code standpoint.

 

I can see alot of places where we can use this while doing ASP.NET at least.

AdamSpeight2008
AdamSpeight2008
The Bandito Coder

That's why it was any Idea. Implementing is the idea down to smarter brains than mine.

Maybe I should have explained in more detail

The idea was when the code is run in "Test Mode" the Test Engine recognises that that class has a Test attribute.

 So read the string part "System.Date,Now" which is interpted to mean that that method is called for by the CLR I want to use the alternative version.

 The alternative version is provided via a func ( The Lamba Expression )

 

Shame about the attributes, having to be a constant expression, because its converted to metadata, I think having a func would be useful.

Imagine you have an AddressOf and point it a function contained in a test module.

Microsoft Communities