Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Dummy used for in FakeItEasy?

What is Dummy used for in FakeItEasy? How does it differ from A.Fake or A.Ignored ?

Thanks :-)

like image 340
schmoopy Avatar asked Oct 18 '11 00:10

schmoopy


1 Answers

A dummy isn't really used for anything by FakeItEasy itself, it's merely a way to create dummy instances that you can use in your tests.

For example, say that you want to test the following class:

public class Foo
{
    public void Bar(DateTime someDate);
}

Now, in one of your tests you want to invoke the bar method but the value that is passed to it is not important to the test, instead of writing:

foo.Bar(new DateTime(2000, 1, 1));

You can write:

foo.Bar(A.Dummy<DateTime>());

This signals that the value is really not important to the test so the whole reason for using it is to communicate intent better.

like image 172
Patrik Hägne Avatar answered Oct 25 '22 21:10

Patrik Hägne