Autofixture ThrowingRecursionBehavior

Sami C.
1 min readFeb 7, 2019

--

AutoFixture is designed to make Test-Driven Development more productive and unit tests more refactoring-safe. It does so by removing the need for hand-coding anonymous variables as part of a test’s Fixture Setup phase. Among other features, it offers a generic implementation of the Test Data Builder pattern.

Let’s say you have a class that has recursion, a person can have a friends property that is a person object.

Autofixture is designed to throw a ThrowingRecursionBehavior to let the developer know that he/she has a circular reference in your code. This is good! Now how to fix this?

The number 1 in the object OmitOnRecursionBehavior represents recursionDepth. This must be greater than 0 or it will throw an exception. Assigning nothing to the OmitOnRecursionBehavior() will take the default which is DefaultRecursionDepth = 1;

That’s all you need! More information can be found on

Happy coding and see you soon!

--

--

Sami C.
Sami C.

Written by Sami C.

Freelance Software Engineer

No responses yet