Skip to content

Commit

Permalink
Use Assert.Fail() instead of Assert.True(false) to fail a test
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed Nov 9, 2023
1 parent d2347d4 commit cda0d8e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Src/Tests/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ public static void ComparePrivateField<InstanceType, FieldType>(InstanceType ins
FieldInfo fi = typeof(InstanceType).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
if (fi is null)
{
Assert.True(false, "The private field was not found.");
Assert.Fail("The private field was not found.");
}

object fieldVal = fi.GetValue(instance);
if (fieldVal is null)
{
Assert.True(false, "The private field value was null.");
Assert.Fail("The private field value was null.");
}
else if (fieldVal is FieldType actual)
{
Assert.Equal(expected, actual);
}
else
{
Assert.True(false, $"Field value is not the same type as expected.{Environment.NewLine}" +
$"Actual type: {fieldVal.GetType()}{Environment.NewLine}" +
$"Expected type: {expected.GetType()}");
Assert.Fail($"Field value is not the same type as expected.{Environment.NewLine}" +
$"Actual type: {fieldVal.GetType()}{Environment.NewLine}" +
$"Expected type: {expected.GetType()}");
}
}

Expand All @@ -60,7 +60,7 @@ public static string ReadResources(string resourceName, string fileExtention = "
}
else
{
Assert.True(false, "File was not found among resources!");
Assert.Fail("File was not found among resources!");
return "";
}
}
Expand Down

0 comments on commit cda0d8e

Please sign in to comment.