I recently started using AutoFixture library (http://autofixture.codeplex.com/) for Unit Testing and I quite like it.
I got this code sample from the AutoFixture CodePlex website. My question is in regards to line number 8.
1. [TestMethod]
2. public void IntroductoryTest()
3. {
4. // Fixture setup
5. Fixture fixture = new Fixture();
6.
7. int expectedNumber = fixture.CreateAnonymous<int>();
8. MyClass sut = fixture.CreateAnonymous<MyClass>();
9.
10. // Exercise system
11. int result = sut.Echo(expectedNumber);
12.
13. // Verify outcome
14. Assert.AreEqual<int>(expectedNumber, result, "Echo");
15. // Teardown
16. }
I can't understand, why we need to create an anonymous object of the class under test.
MyClass sut = fixture.CreateAnonymous<MyClass>();
The class should be the real object IMO. For an example..
var sut = new MyClass();
My question is, what is the real benefit of creating an anonymous object to test against?