Showing posts with label testing. Show all posts
Showing posts with label testing. Show all posts

17 October 2012

How to generate missing Fakes shims

While using the Fakes (Moles) isolation framework, you will notice some mscorlib shims are missing, particularly in the System namespace. For example, System.Fakes.ShimEnvironment does not exist. Although these are missing by default, you can request the compiler to generate shims for specific objects. This post provides steps to request Fakes shim generation for System.Environment and an example of implementation.

This tutorial targets Microsoft Fakes Isolation Framework on Visual Studio 2012 Ultimate or later; but, this process is also compatible with the developmental version, project name "Moles", running on Visual Studio 2008 or 2010. This tutorial assumes you have basic understanding of the MSTest framework.

20 September 2012

Fakes added to Moles posts

Today, I am (finally) starting to update all of my posts on use of the Moles Isolation Framework to its official release version, called "Fakes Framework", included in Visual Studio 2012 Ultimate and newer.

To learn how to use both Moles and Fakes, click the "Unit Testing with Fakes/Moles Framework" link, below the page title on this blog.  Please bear with me, while I get the information updated.  I am very glad to see Moles come to market!

24 October 2011

How Do I Make My Build and/or Test Servers Use Pex and Moles?

All build and test servers (e.g. MSBuild) that must handle Pex and/or Moles have the Pex and Moles Framework installed.  After installation, the builds and tests should execute normally.

22 October 2011

How do I make my test use Moles?

NOTE: The Moles isolation framework must be installed to any machine that will compile the solution and/or execute the mole tests.

The following things must be done, to use Moles in a test.  This looks like a lot, now.  However, you'll quickly get the hang of things, and have these steps done in seconds!  Using my CodeRush Moles templates will help speed things up.

15 June 2011

Introducing Moles and PEX

*NOTE: I am compiling materials for Pex/Moles presentations, and will post them here.  Production of the remainder of this series of posts is on hold, until then.  Sorry!


Microsoft's Research in Software Engineering (RiSE) has been developing a pair of unit testing technologies for the past several years, named MOLES and PEX.  Awareness and pre-market adoption of these technologies is being increasingly adopted by the programming community.

UPDATE:  Please see the new Testing with Pex and Moles page, that contains links to all related posts!

31 May 2011

How to Mole a Specific Type Instance

So, you're using Moles for unit test dependency isolation.  You have a method to test that (unavoidably) uses several instances of the same type.  You determine a unit test must be created to test that each instance must be tested individually.  Moles is perfect for detouring calls to the API or .NET Framework dependency, but how do you mole a single instance of the common type, instead of all instances of the type?

Moles requires tests to be IN an instrumented process

After adopting Moles as my dependency isolation utility of choice for .NET projects, I began to encounter an exception that could not be explained by anyone, including Peli:
Moles requires tests to be IN an instrumented process.

To compound my frustration, my unit tests involving "moled" types began to work sometimes, and would work other times.  To add frustration, no code changes took place between the successful and unsuccessful test executions.

But something had indeed changed.  Not in the code.  Not on my workstation. Not in Visual Studio 2010 or Team Foundation Server.  How I executed the text changed.

25 May 2011

How to Stub Dependency Event Handlers in Integration Tests

Integration tests help you ensure dependencies behave as expected.  When creating unit tests, developers go to great lengths to eliminate dependencies, but that's not our objective.  The application should already have passed unit tests, before proceeding with integration tests. We want to ensure that integrating the application with its dependencies works as expected.

"Dependencies" includes other modules, APIs, frameworks, hardware, databases, networks, etc.  We want to ensure the application works with these other resources as expected.  This demonstration code implements constructor injection, to simplify testing.  Dependency injection is essential to unit testing, but also proves useful for integration testing.  The injection is important, because we want to isolate a specific dependency and inject a controlled mock object for others.

12 April 2011

Unit Testing with Moles and Pex - Part 1

This post discusses key ways of improving the effectiveness and code coverage on unit tests, using the Visual Studio Test Framework, including the developing Moles and Pex technologies.  Other frameworks and harnesses such as nUnit, Moq, etc. are not discussed in this post.

Moles is Microsoft's code instrumentation, or mock framework, used to isolate environment dependencies.  Moles was created expressly to enable Pex to function.  Moles is discussed in greater detail, after the break.

Pex intelligently examines the logic branches of the code to be tested, and then generates a series of input values that should or should not fail, thereby maximizing test code coverage.

Before we start talking about Moles and Pex, there are some elementary, yet vitally important topics to review about unit testing.  Adhering to these rules play into the effectiveness of Moles and Pex.  I strongly advise reading, before moving on to part 2, but I really can't stop you, can I? (or can I? Muahaha!)