nsubstitute / NSubstitute

A friendly substitute for .NET mocking libraries.
https://nsubstitute.github.io
Other
2.67k stars 263 forks source link

Support for Partial Mocks #41

Closed dtchepak closed 10 years ago

dtchepak commented 13 years ago

http://stackoverflow.com/questions/4600825/does-nsubstitute-support-the-idea-of-partial-mocks

http://www.ayende.com/wiki/Rhino+Mocks+Partial+Mocks.ashx

dgg commented 12 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.

dtchepak commented 12 years ago

@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

dgg commented 12 years ago

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

ikhavkin commented 12 years ago

Looks like I miss this too.

Restuta commented 12 years ago

+1

dtchepak commented 12 years ago

@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?

worldspawn commented 11 years ago

+1

arialdomartini commented 11 years ago

-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 ;)

rsenna commented 11 years ago

+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).

grzesiek-galezowski commented 11 years ago

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.

artgo commented 11 years ago

+1

bradwilson commented 11 years ago

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.

SimonCropp commented 10 years ago

should this be closed http://nsubstitute.github.io/help/partial-subs/ ?

dtchepak commented 10 years ago

I think so, any enhancements can be logged under a different issue. Thanks @SimonCropp.

SimonCropp commented 10 years ago

community driven housekeeping FTW

dtchepak commented 10 years ago

:+1: