Course info
Apr 4, 2015
1h 58m

The open source AutoFixture library helps reduce the amount of unnecessary code in the arrange phases of test code. It does this by automatically supplying values for test data that are required for the test to function, but where the exact value is unimportant. In addition to simple types, AutoFixture also creates object graphs of test data, reducing the amount of test code that needs to be written and reducing the chances that tests will break compilation when changes are made to production code.

About the author
About the author

With over 15 years experience, Jason Roberts is a Microsoft .NET MVP, freelance developer, and author.

More from the author
Mocking with Moq and NUnit
1h 53m
Feb 22, 2019
Introduction to .NET Testing with NUnit 3
2h 6m
Dec 17, 2018
More courses by Jason Roberts
Section Introduction Transcripts
Section Introduction Transcripts

Introducing AutoFixture
Hi. I'm Jason Roberts from Pluralsight. Welcome to this course on Better. NET Unit Tests with AutoFixture. In this course we're going to be looking at the open source AutoFixture library and we're going to learn how this library can improve our unit tests in a number of different ways. By the end of this course, we'll learn how to use AutoFixture to create anonymous test data. so, for example, this test where we're subtracting the value 1, we'll essentially be able to turn into something that looks more like this. So even though in this example it's a very simple test, we can start to see a number of benefits of AutoFixture.

Creating Anonymous Test Data
Hi. Welcome back. In this module we're going to look in a bit more detail about how we create anonymous test data of various types. So in this module we're going to start off by seeing how we can create anonymous strings and numbers. We'll also learn how we can use AutoFixture to create anonymous DateTime and TimeSpan instances. We'll learn that in addition to creating a single instance of a piece of anonymous data. We can also create collections or sequences of anonymous data and we'll learn that as well as creating instances of simple types. AutoFixture will also populate complete object graphs with anonymous test data. In this module we'll also learn that if we're using AutoFixture to create an instance of an object, which has data annotations applied, in what circumstances AutoFixture will respect these data annotations.

Customizing Object Creation
Hi. Welcome back. In the previous module we saw how we can use AutoFixture to create anonymous objects of different types, but we didn't attempt to take control of exactly how AutoFixture will be creating these anonymous objects. In this module we're going to learn how we can exercise more control over the creation of anonymous objects. In this module we're going to start off by looking at how we can customize the individual fixture instances that we create in our tests, so once we've created our fixture instance in our test code, we can tell AutoFixture to return a specific instance for a specific type of object. Next we'll learn how we can take control and customize the building of an individual object using a fixture. We'll then get a brief overview of how the AutoFixture pipeline works and how when a request comes in, AutoFixture satisfies this request and produces an anonymous object. We'll then learn how we can create a class that we can inject into the AutoFixture pipeline to customize object creation.

Writing Less Test Code and Improving Test Maintenance
Hi. Welcome back to this final module. In this module we're going to learn how we can use AutoFixture to result in less test code and how by using AutoFixture we can improve overall test maintenance and make our code more refactor safe. So to start off, in this module we're going to be looking at an example where our tests don't use AutoFixture and then we're going to go and change some production code and see that the existing tests break. We'll then reset the production code back to its previous state, refactor the unit tests to this time use AutoFixture, and then perform the same modification to the production code and notice that with using AutoFixture we no longer have to go and change all of the existing tests. Next we're going to learn how if we're using parameterized tests in xUnit. net how we can introduce AutoFixture in this use case and how we can actually get AutoFixture to inject anonymous values into our parameterized tests. In this module we'll also see how we can use AutoFixture as an auto mocking framework and how we can combine AutoFixture with the MoqU mocking framework and also the Rhino Mocks mocking framework. So we'll learn how we can configure AutoFixture to not only create our system under test, but also satisfy any dependencies of the system under test with mock objects. Finally, we'll see how we can combine the auto anonymous data approach and the auto mocking approach to greatly reduce the amount of test code in our arrange phase.