Recently Microsoft research lab announced Moles stubbing framework that comes tightly with Pex (http://research.microsoft.com/en-us/projects/pex/). I really do not see profits in using Pex on real projects, but Moles is quite interesting.
Features of Moles:
1) It can create all types of test doubles except of mocks. Personally I do not accept mockist style of unit testing, so I consider absence of mocks as advantage.
2) It uses delegates to define behavior of test doubles. Like Moq does. Sweet :)
4) It can be used with any testing framework, like NUnit, MBUnit, xUnit. Of course it does – in other case nobody will use it!
5) And the last and most significant feature – it can replace any class with test double, even static one! Before this moment only one framework was to able do it – typemock for just 800 $ per license. They call such test doubles “Moles” and mole for DateTime.Now will look like:
Finally covering legacy code with unit tests will be not so painful :)
Links for farther reading:
http://angler.wordpress.com/2010/01/21/pex-and-moles-untestable-code-not-really
http://research.microsoft.com/en-us/projects/pex/documentation.aspx
http://research.microsoft.com/en-us/projects/pex/molestutorial.docx
http://research.microsoft.com/en-us/projects/pex/molesmanual.docx
Update: Answer to question "Is Pex (Test generation) really usefull tool?" is here http://stackoverflow.com/questions/2704669/is-pex-test-generation-really-usefull-tool
Features of Moles:
1) It can create all types of test doubles except of mocks. Personally I do not accept mockist style of unit testing, so I consider absence of mocks as advantage.
2) It uses delegates to define behavior of test doubles. Like Moq does. Sweet :)
var fileSystem = new SIFileSystem() { ReadAllTextString = filename => { Assert.AreEqual(fileName, file); return content; } };3) It uses pre-compile time code generation to create classes for doubles.
4) It can be used with any testing framework, like NUnit, MBUnit, xUnit. Of course it does – in other case nobody will use it!
5) And the last and most significant feature – it can replace any class with test double, even static one! Before this moment only one framework was to able do it – typemock for just 800 $ per license. They call such test doubles “Moles” and mole for DateTime.Now will look like:
MDateTime.NowGet = () => new DateTime(2010, 1, 20);
Finally covering legacy code with unit tests will be not so painful :)
Links for farther reading:
http://angler.wordpress.com/2010/01/21/pex-and-moles-untestable-code-not-really
http://research.microsoft.com/en-us/projects/pex/documentation.aspx
http://research.microsoft.com/en-us/projects/pex/molestutorial.docx
http://research.microsoft.com/en-us/projects/pex/molesmanual.docx
Update: Answer to question "Is Pex (Test generation) really usefull tool?" is here http://stackoverflow.com/questions/2704669/is-pex-test-generation-really-usefull-tool