Unplanned
Last Updated: 08 Feb 2024 18:32 by Ivo
Ivo
Created on: 08 Feb 2024 18:32
Type: Bug Report
0
JustMock is slow when AutoFixture is used between the arrange

The issue is about interoperability between JustMock and AutoFixture. The unit test run can be 90% faster if all the fixtures are created before the JustMock arrangements.

Here is a sample code that figures out the issue:

[Fact]
public void Slow
{ 
    var fixture = new Fixture():

    var items1 = fixture.Create<List<Item>>();
    Nock.Arrange(() => ItemsRepository.GetItems1()).Returns(items1);

    var items2 = fixture.Create<List<Item>>();
    Nock.Arrange(() => ItemsRepository.GetItems2()).Returns(items2);

    var items3 = fixture.Create<List<Item>>();
    Nock.Arrange(() => ItemsRepository.GetItems3()).Returns(items3);

    var items4 = fixture.Create<List<Item>>();
    Nock.Arrange(() => ItemsRepository.GetItems4()).Returns(items4);
}

[Fact]
public void Fast()
{
    var fixture = new Fixture():

    var items1 = fixture.Create<List<Item>>();
    var items2 = fixture.Create<List<Item>>();
    var items3 = fixture.Create<List<Item>>();
    var items4 = fixture.Create<List<Item>>();

    Nock.Arrange(() => ItemsRepository.GetItems1()).Returns(items1);
    Nock.Arrange(() => ItemsRepository.GetItems2()).Returns(items2);
    Nock.Arrange(() => ItemsRepository.GetItems3()).Returns(items3);
    Nock.Arrange(() => ItemsRepository.GetItems4()).Returns(items4);
}

The test duration should not be dependent on the exact implementation.

0 comments