Should I be using AutoFixture to test the Core element of my Onion, which has no dependancies?
Asked Answered
G

1

2

This question follows on from my previous question here: How to use OneTimeSetup? and specifically one of the answerers answer. Please see the code below:

[TestFixture]
public class MyFixture
{
    IProduct Product;

    [OneTimeSetUp]
    public void OneTimeSetUp()
    {
        IFixture fixture = new Fixture().Customize(new AutoMoqCustomization());
        Product = fixture.Create<Product>();
    }
    //tests to follow
}

Is AutoMoq used to create mocks only? The reason I ask is because I was reading a question on here earlier where the answerer implied that it is also used to create normal types i.e. not Mocks.

I want to test the Core element of my Onion, which has no dependencies. Therefore should I be using AutoFixture?

Galvano answered 22/1, 2018 at 19:23 Comment(0)
I
3

The AutoMoq Glue Library gives AutoFixture the additional capabilities of an Auto-Mocking Container; that is, not only can it compose normal objects for you - it can also supply mock objects to your objects, should they be so required.

AutoFixture itself is not an Auto-Mocking Container, but rather a library that automates the Fixture Setup phase of the Four Phase Test pattern, as described in xUnit Test Patterns. It also enables you to automate code associated with the Test Data Builder pattern.

It was explicitly designed as an alternative to Implicit Setup, so I think it makes little sense to use it together with a setup method and mutable class field as this question suggests. In other words, the whole point of AutoFixture is that it enables you to write independent unit tests like this:

[TestFixture]
public class MyFixture
{
    [Test]
    public void MyTest()
    {
        var fixture = new Fixture().Customize(new AutoMoqCustomization());
        var product = fixture.Create<Product>();

        // Use product, and whatever else fixture creates, in the test
    }
}

You definitely can use it to test your units even when they have no dependencies, but in that case, you probably don't need the AutoMoq Customization.

Immunogenic answered 22/1, 2018 at 21:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.