Skip to content

Is there a built-in option to have AutoFixture randomly supply null instead of a value? #1412

Answered by aivascu
macfma01 asked this question in Q&A
Discussion options

You must be logged in to vote

@macfma01 no there isn't such an option however I think you might be interested in the AutoFixture.Idioms package.
The idioms encapsulate entire tests that you'd otherwise implement manually. One of these examples happens to be guard clause assertions (null checks).

Here's an example:

public class SomeEntity
{
    public SomeEntity(Guid uuid, string value)
    {
        Uuid = uuid;
        Value = value;
    }

    public Guid Uuid { get; }
    public string Value { get; private set; }

    public void DoStuff(string value)
    {
        this.Value = value;
    }
}

The test below will attempt to provide the default value to each arguments of each public constructor.

[Theory]
[AutoData]
p…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by macfma01
Comment options

You must be logged in to vote
1 reply
@aivascu
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants