C
C#9mo ago
salty_pepper

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
Yawnder
Yawnder9mo ago
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.
salty_pepper
salty_pepperOP9mo ago
@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.
Yawnder
Yawnder9mo ago
Perfect
salty_pepper
salty_pepperOP9mo ago
@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.
Yawnder
Yawnder9mo ago
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.
salty_pepper
salty_pepperOP9mo ago
No worries, thank you. I'll do that/
Yawnder
Yawnder9mo ago
Take care!
Want results from more Discord servers?
Add your server