Goal
Create a method that first creates a file and then deletes it. Sounds pretty useless but it makes a good example.
This tutorial is written in C#. You can use any mock object and unit test frameworks of your choice. In this example we're using
Rhino Mocks and
MbUnit v3.
Steps
- Create sample project.
- Create unit test.
- Create actual method.
Create sample project.
- Create new Class Library project and name it SysWrapSample.
- Add reference to your mock object framework. If you're using Rhino mocks, click on Browse tab in Add Reference dialog and reference to Rhino.Mocks.dll.
- Add reference to your unit test framework. If you're using MbUnit v3, click on .NET tab in Add Reference dialog and select Gallio and MbUnit.
- Add the last reference to SystemWrapper.dll.
- Rename Class1 class into FileInfoSample.
- Add using statements for SystemWrapper.IO, MbUnit.Framework, and Rhino.Mocks. Your class should look like this:
using SystemWrapper.IO;
using MbUnit.Framework;
using Rhino.Mocks;
namespace SysWrapSample
{
public class FileInfoSample
{
}
}
Create unit test.