Are we supposed to test factory pattern in unit test?
Suppose we have some code that does something, during the execution it calls the factory class to create an instance depending on some property.
Do we just mock the factory class in unit test? Or should we test whether the factory class is returning the right type of object?
7 Replies
In a perfect world, you test everything. In the real world, you start with high priority (high risk or high consequences code) first.
If the code of that factory is basically a switch, I wouldn't care much. If the logic is heavy and can result is significantly different objects, then maybe.
@Yawnder - [▰▱▱▱▱] Thanks, after some thoughts I decide to not test the factory method. I don't mock the factory method in the unit test, instead injecting the actual factory class into the class that needs it.
Perfect
@Yawnder - [▰▱▱▱▱] Sorry this might sound out of the blue. Are you an experienced dev? I'm working on a refactoring assignment and looking for someone to do a quick live code review to point out whether there are any major flaws design wise if that's alright. It would take no more than 15 min.
I'm experienced yes, but I don't want to commit that amount of time, especially not at 2h35 am. I suggest you open a thread in #code-review
You can ask in your post that you would like a live review too
Nothing wrong with that.
No worries, thank you. I'll do that/
Take care!