-
It's realistic in some tests for some of the object properties to be null. AutoFixture seems to always supply a value for each type. Can it be set to alternate between values and nulls so that null cases are covered in the tests. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@macfma01 no there isn't such an option however I think you might be interested in the 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 [Theory]
[AutoData]
public void GuardsConstructorArguments(GuardClauseAssertion assertion)
{
assertion.Verify(typeof(SomeEntity).GetConstructors());
} It could even test your entire type, including constructor, methods, and properties. [Theory]
[AutoData]
public void GuardsConstructorArguments(GuardClauseAssertion assertion)
{
assertion.Verify(typeof(SomeEntity).GetConstructors());
} Keep in mind that the idioms package is highly opinionated in the implementation of it's default assertions, but you could use it to implement your own (less strict assertions). |
Beta Was this translation helpful? Give feedback.
-
I thought I was on to something with this. [<Fact>]
member this.``AutoFixture test`` () =
fixture.Register<string>(fun x ->
let rnd = System.Random()
if rnd.Next(0, 100) < 50 then
fixture.Create<string>()
else
null)
let result = fixture.Create<string>()
output.WriteLine($"result: {result}")
test <@ result = null || result <> null @> But it doesn't like me calling
|
Beta Was this translation helpful? Give feedback.
@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:
The test below will attempt to provide the
default
value to each arguments of each public constructor.