Question

Fakes testing framework is probably available only on Premium and Ultimate editions of Viual Studio. However, is there any other difference compared to MS Unit testing framework?

Was it helpful?

Solution

You use MS's Unit Testing Framework to write unit tests within Visual Studio. Here's a basic class that you could use as a guideline:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            // Arrange

            // Act

            // Assert
        }
    }
}

If you find that your unit tests have a lot of dependencies you would use something like Microsoft Fakes to isolate just the pieces of code you really need to test. If you are using TDD and you are unit testing code that relies on other code that isn't complete yet you can use Fakes to mock the incomplete code as well.

From Isolating Code Under Test with Microsoft Fakes:

Fakes come in two flavors:

A stub replaces a class with a small substitute that implements the same interface. To use stubs, you have to design your application so that each component depends only on interfaces, and not on other components. (By "component" we mean a class or group of classes that are designed and updated together and typically contained in an assembly.)

A shim modifies the compiled code of your application at run time so that instead of making a specified method call, it runs the shim code that your test provides. Shims can be used to replace calls to assemblies that you cannot modify, such .NET assemblies.

You use Microsoft Fakes inside your unit tests.

Here's a great resource for Microsoft Fakes: http://vsartesttoolingguide.codeplex.com/releases/view/102290

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top