Closed dtchepak closed 10 years ago
I already responded to the question in http://stackoverflow.com/questions/4600825/does-nsubstitute-support-the-idea-of-partial-mocks but I think NSubstitute (v 1.3.0.0) can handle partial mocks as I understand them just fine.
@dgg,
Partial mocks are a bit different. They allow you to selectively call the base implementation. Virtual calls get intercepted/recorded, but are optionally forwarded to the original implementation as well.
NSubstitute currently does not support this; the original implementation is never called for virtual methods.
Regards, David
Ok, I did not realise that virtual methods are always substituted and the real implementation is never called as in my case I was always substituting the behavior of the virtual method.
Thanks
Looks like I miss this too.
+1
@ikhavkin @Restuta, I won't get a chance to look at this for a while. If you get a chance could you spike something out and send it through to me?
+1
-1 Personally, when I feel the need of a partial mock I always wonder if there's a missing dependency in my class.
I love NSubstitute since it is so damn clean, easy, powerful and pure.
Partial Mocks (and, to be honest, Checking call order) seem to me nick-nacks that shouldn't be in the core library, since they somehow foster anti-patterns.
Just my 2 cents. I will continue loving NSubstitute anyway ;)
+1 I agree that the need for a partial mock indicates a potential problem in your code base.
BUT it is useful, even essential for refactoring legacy code (after all, you need give a smelly piece of code some test coverage before trying to improve it).
Hi, my +1 on this.
Mocking frameworks are sometimes used as tools that aid design (sometimes called need-driven development) and sometimes as tools of isolation (in scenarios where there is existing code without any tests). While I personally believe the main purpose is the first one, the latter is still a very important scenario and supporting it may be a an enabler for people to start TDD or unit testing.
Quoting Roy Osherove: "I don't rely on my tools to teach me design". Hence, as a mere NSubstitute user, I vote to add this functionality.
+1
If looking for syntax, perhaps Substitute.Partial<T>()
would be appropriate, since you don't have a property to hang off like Moq does.
Also +1 that this is a useful feature for legacy code.
should this be closed http://nsubstitute.github.io/help/partial-subs/ ?
I think so, any enhancements can be logged under a different issue. Thanks @SimonCropp.
community driven housekeeping FTW
:+1:
http://stackoverflow.com/questions/4600825/does-nsubstitute-support-the-idea-of-partial-mocks
http://www.ayende.com/wiki/Rhino+Mocks+Partial+Mocks.ashx