tag:blogger.com,1999:blog-5359546512544809971.post5884482491280575673..comments2024-03-18T23:01:00.513-07:00Comments on Jeremy Bytes: Unit Test Factory Methods: Return an Interface or a Mock?Jeremyhttp://www.blogger.com/profile/06749690234470413216noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-5359546512544809971.post-52417794560246603612019-02-05T16:53:22.591-08:002019-02-05T16:53:22.591-08:00Thanks Dror, just wanted to mention, your link to ...Thanks Dror, just wanted to mention, your link to Mocking Explained publication you wrote in Oct 2013 is dead link. Any chance to fix that and thank again :)deleted_profilehttps://www.blogger.com/profile/05404174359693654886noreply@blogger.comtag:blogger.com,1999:blog-5359546512544809971.post-5654036957388329272016-06-30T06:02:21.644-07:002016-06-30T06:02:21.644-07:00Hi Dror, Great article -- the first sentence is wh...Hi Dror, Great article -- the first sentence is what I'm constantly thinking about. I've been using Option #2 with factory methods (obviously). In the example here, I don't care about the behavior of the ILogger, but when I do, I set that behavior in the factory method rather than in the test itself (hopefully the dependencies aren't affecting the behavior of the tests too much -- but that sounds like another article).<br /><br />You're the second person to recommend AutoFixture, so it's definitely something that I need to look into (and I've generally liked the approaches that Mark Seemann uses). I'll admit that my initial reaction is a bit divided. But I'll reserve judgment until I have a chance to work with it.<br /><br />Thank you for taking the time to pass along your experience and recommendation. This is how we get better as a community.<br />-JeremyJeremyhttps://www.blogger.com/profile/06749690234470413216noreply@blogger.comtag:blogger.com,1999:blog-5359546512544809971.post-19523133136025768612016-06-30T04:23:10.919-07:002016-06-30T04:23:10.919-07:00I can't speak for Roy but as someone who did a...I can't speak for Roy but as someone who did a few projects with him I think he no longer cares about "Stub" or "Mock" - rather he prefers to use "Fake objects" (and so do I).<br />Another point to make clear is that when using Moq if you return ILogger and need to set a behavior on that "Fake" object you cannot. In this case you must return Mock instead. Some like this kind of behavior some don't but it will affect how you structure your factory methods. <br />Lastly IMHO there are better ways to initialize objects in your test namely autoMocking (AutoFaking?) container: http://blog.drorhelper.com/2013/12/on-object-creation-and-unit-tests.html<br /><br />Check it out and let me know what you think.<br /><br />Happy coding...Anonymoushttps://www.blogger.com/profile/04664241287712801778noreply@blogger.com