سؤال

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

Thanks :-)

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

@Patrik Hägne's answer describes how users may use a Dummy, but there's another part to the story. FakeItEasy does make use of Dummies.

When FakeItEasy has to create a Fake class instance (or sometimes another Dummy class instance) by invoking one of the class's constructors, and the constructor takes arguments, it will use Dummies for the arguments.

I encourage you to check out the Dummies documentation.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top