What is Dummy used for in FakeItEasy? How does it differ from A.Fake or A.Ignored ?
Thanks :-)
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.
Dummy
is the low level version of A<>.Ignored
? The latter makes much more sense to use then. –
Sixtieth A<T>.Ignored
is supplied by users to assert that a call is made. It will match any argument supplied to a call (good for when you only care about some of the other arguments). You can only use A<>.Ignore inside an assertion. I would never use a Dummy inside an assertion, as it will cause FakeItEasy to perform an equality check against the value, and if the argument it was checking ever changed in the future, the test would fail. –
Foiled © 2022 - 2024 — McMap. All rights reserved.