Skip to content

Commit

Permalink
Improve tests by making them immune to mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrzajac committed Sep 27, 2023
1 parent 144dbd1 commit b8366af
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests.Attributes
{
using System;
using System.Collections.Generic;
using System.Reflection;

Expand Down Expand Up @@ -80,16 +79,24 @@ public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ign
}

[AutoMockData]
[Theory(DisplayName = "GIVEN test method has some parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeParameters_WhenTestRun_ThenParametersAreGenerated(int value, IDisposable disposable)
[Theory(DisplayName = "GIVEN test method has some value parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeValueParameters_WhenTestRun_ThenParametersAreGenerated(int value)
{
// Arrange
// Act
// Assert
value.Should().NotBe(default);
}

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().Contain("Proxy", "that way we know it was mocked.");
[AutoMockData]
[Theory(DisplayName = "GIVEN test method has some object parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeObjectParameters_WhenTestRun_ThenParametersAreGenerated(IFakeObjectUnderTest value)
{
// Arrange
// Act
// Assert
value.Should().NotBeNull();
value.StringProperty.Should().NotBeNullOrEmpty();
}

protected void MethodUnderTest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests.Attributes
{
using System;
using System.Collections.Generic;
using System.Reflection;

Expand Down Expand Up @@ -114,15 +113,19 @@ public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ign

[InlineAutoMockData(100)]
[Theory(DisplayName = "GIVEN test method has some inline parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeInlineParameters_WhenTestRun_ThenParametersAreGenerated(int value, IDisposable disposable)
public void GivenTestMethodHasSomeInlineParameters_WhenTestRun_ThenParametersAreGenerated(
int firstValueInstance,
int secondValueInstance,
IFakeObjectUnderTest objectInstance)
{
// Arrange
// Act
// Assert
value.Should().Be(100);
firstValueInstance.Should().Be(100);
secondValueInstance.Should().NotBe(default);

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().Contain("Proxy", "that way we know it was mocked.");
objectInstance.Should().NotBeNull();
objectInstance.StringProperty.Should().NotBeNullOrEmpty();
}

protected void MethodUnderTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ public void GivenUninitializedMemberName_WhenConstructorIsInvoked_ThenExceptionI

[Theory(DisplayName = "GIVEN test method has some member generated parameters WHEN test run THEN parameters are provided")]
[MemberAutoMockData(nameof(TestData))]
public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenParametersAreProvided(int first, int second, int third, int fourth, IDisposable disposable)
public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenParametersAreProvided(
int first,
int second,
int third,
int fourth,
IFakeObjectUnderTest objectInstance)
{
// Arrange
var testData = TestData.ToList();
Expand All @@ -176,8 +181,8 @@ public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenPara
third.Should().BeOneOf((int)testData[0][2], (int)testData[1][2], (int)testData[2][2]);
fourth.Should().NotBe(default);

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().Contain("Proxy", "that way we know it was mocked.");
objectInstance.Should().NotBeNull();
objectInstance.StringProperty.Should().NotBeNullOrEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Objectivity.AutoFixture.XUnit2.AutoFakeItEasy.Tests
{
public interface IFakeObjectUnderTest
{
public string StringProperty { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Objectivity.AutoFixture.XUnit2.AutoMoq.Tests.Attributes
{
using System;
using System.Collections.Generic;
using System.Reflection;

Expand Down Expand Up @@ -80,16 +79,24 @@ public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ign
}

[AutoMockData]
[Theory(DisplayName = "GIVEN test method has some parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeParameters_WhenTestRun_ThenParametersAreGenerated(int value, IDisposable disposable)
[Theory(DisplayName = "GIVEN test method has some value parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeValueParameters_WhenTestRun_ThenParametersAreGenerated(int value)
{
// Arrange
// Act
// Assert
value.Should().NotBe(default);
}

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().StartWith("IDisposableProxy", "that way we know it was mocked.");
[AutoMockData]
[Theory(DisplayName = "GIVEN test method has some object parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeObjectParameters_WhenTestRun_ThenParametersAreGenerated(IFakeObjectUnderTest value)
{
// Arrange
// Act
// Assert
value.Should().NotBeNull();
value.StringProperty.Should().NotBeNullOrEmpty();
}

protected void MethodUnderTest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Objectivity.AutoFixture.XUnit2.AutoMoq.Tests.Attributes
{
using System;
using System.Collections.Generic;
using System.Reflection;

Expand Down Expand Up @@ -114,15 +113,19 @@ public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ign

[InlineAutoMockData(100)]
[Theory(DisplayName = "GIVEN test method has some inline parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeInlineParameters_WhenTestRun_ThenParametersAreGenerated(int value, IDisposable disposable)
public void GivenTestMethodHasSomeInlineParameters_WhenTestRun_ThenParametersAreGenerated(
int firstValueInstance,
int secondValueInstance,
IFakeObjectUnderTest objectInstance)
{
// Arrange
// Act
// Assert
value.Should().Be(100);
firstValueInstance.Should().Be(100);
secondValueInstance.Should().NotBe(default);

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().StartWith("IDisposableProxy", "that way we know it was mocked.");
objectInstance.Should().NotBeNull();
objectInstance.StringProperty.Should().NotBeNullOrEmpty();
}

protected void MethodUnderTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ public void GivenUninitializedMemberName_WhenConstructorIsInvoked_ThenExceptionI

[Theory(DisplayName = "GIVEN test method has some member generated parameters WHEN test run THEN parameters are provided")]
[MemberAutoMockData(nameof(TestData))]
public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenParametersAreProvided(int first, int second, int third, int fourth, IDisposable disposable)
public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenParametersAreProvided(
int first,
int second,
int third,
int fourth,
IFakeObjectUnderTest objectInstance)
{
// Arrange
var testData = TestData.ToList();
Expand All @@ -176,8 +181,8 @@ public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenPara
third.Should().BeOneOf((int)testData[0][2], (int)testData[1][2], (int)testData[2][2]);
fourth.Should().NotBe(default);

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().StartWith("IDisposableProxy", "that way we know it was mocked.");
objectInstance.Should().NotBeNull();
objectInstance.StringProperty.Should().NotBeNullOrEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Objectivity.AutoFixture.XUnit2.AutoMoq.Tests
{
public interface IFakeObjectUnderTest
{
public string StringProperty { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests.Attributes
{
using System;
using System.Collections.Generic;
using System.Reflection;

Expand Down Expand Up @@ -79,16 +78,24 @@ public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ign
}

[AutoMockData]
[Theory(DisplayName = "GIVEN test method has some parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeParameters_WhenTestRun_ThenParametersAreGenerated(int value, IDisposable disposable)
[Theory(DisplayName = "GIVEN test method has some value parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeValueParameters_WhenTestRun_ThenParametersAreGenerated(int value)
{
// Arrange
// Act
// Assert
value.Should().NotBe(default);
}

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().StartWith("ObjectProxy", "that way we know it was mocked.");
[AutoMockData]
[Theory(DisplayName = "GIVEN test method has some object parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeObjectParameters_WhenTestRun_ThenParametersAreGenerated(IFakeObjectUnderTest value)
{
// Arrange
// Act
// Assert
value.Should().NotBeNull();
value.StringProperty.Should().NotBeNullOrEmpty();
}

protected void MethodUnderTest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests.Attributes
{
using System;
using System.Collections.Generic;
using System.Reflection;

Expand Down Expand Up @@ -113,15 +112,19 @@ public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ign

[InlineAutoMockData(100)]
[Theory(DisplayName = "GIVEN test method has some inline parameters WHEN test run THEN parameters are generated")]
public void GivenTestMethodHasSomeInlineParameters_WhenTestRun_ThenParametersAreGenerated(int value, IDisposable disposable)
public void GivenTestMethodHasSomeInlineParameters_WhenTestRun_ThenParametersAreGenerated(
int firstValueInstance,
int secondValueInstance,
IFakeObjectUnderTest objectInstance)
{
// Arrange
// Act
// Assert
value.Should().Be(100);
firstValueInstance.Should().Be(100);
secondValueInstance.Should().NotBe(default);

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().StartWith("ObjectProxy", "that way we know it was mocked.");
objectInstance.Should().NotBeNull();
objectInstance.StringProperty.Should().NotBeNullOrEmpty();
}

protected void MethodUnderTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ public void GivenUninitializedMemberName_WhenConstructorIsInvoked_ThenExceptionI

[Theory(DisplayName = "GIVEN test method has some member generated parameters WHEN test run THEN parameters are provided")]
[MemberAutoMockData(nameof(TestData))]
public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenParametersAreProvided(int first, int second, int third, int fourth, IDisposable disposable)
public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenParametersAreProvided(
int first,
int second,
int third,
int fourth,
IFakeObjectUnderTest objectInstance)
{
// Arrange
var testData = TestData.ToList();
Expand All @@ -175,8 +180,8 @@ public void GivenTestMethodHasSomeMemberGeneratedParameters_WhenTestRun_ThenPara
third.Should().BeOneOf((int)testData[0][2], (int)testData[1][2], (int)testData[2][2]);
fourth.Should().NotBe(default);

disposable.Should().NotBeNull();
disposable.GetType().Name.Should().StartWith("ObjectProxy", "that way we know it was mocked.");
objectInstance.Should().NotBeNull();
objectInstance.StringProperty.Should().NotBeNullOrEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Objectivity.AutoFixture.XUnit2.AutoNSubstitute.Tests
{
public interface IFakeObjectUnderTest
{
public string StringProperty { get; set; }
}
}

0 comments on commit b8366af

Please sign in to comment.