left-icon

FakeItEasy Succinctly®
by Michael McCarthy

Previous
Chapter

of
A
A
A

CHAPTER 4

Creating a Fake

Creating a Fake


This will be the shortest chapter in the book by far, mainly because FakeItEasy makes it very easy for us to create a fake.

How to Create a Fake

Creating a fake is very straightforward (we’ve already seen this done in previous sections of this book). Use A.Fake<T> in order to get your fake created. You can create a fake of an interface or class.

Faking an interface:

public interface IAmAnInterface

{

    void DoSomething();

}

[TestFixture]
public class WhenFakingAnInterface

{

    [SetUp]

    public void Given()

    {

        var aFakeInterface = A.Fake<IAmAnInterface>();

    }
}

Code Listing 21: Creating a fake of an interface

Faking a class:

public class AClass

{

    public virtual void DoSomething()

    {

        //some implementation

    }

}

[TestFixture]

public class WhenFakingAClass

{

    [SetUp]

    public void Given()

    {

        var aFakeClass = A.Fake<AClass>();

    }

}

Code Listing 22: Creating a fake of a class

Following the rules outlined in Chapter 3, it’s pretty simple to create a fake. But now that we’ve created a fake, what exactly can we do with it?

Scroll To Top
Disclaimer
DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.