Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to implement partial mocking? #29

Closed
AlexLuya opened this issue Dec 18, 2013 · 3 comments
Closed

Is it possible to implement partial mocking? #29

AlexLuya opened this issue Dec 18, 2013 · 3 comments

Comments

@AlexLuya
Copy link

I think it may be impossible,but I am want to share my thought,for example

func (s *impl) test() {
if needToPartialMocked() {
doSomething()
}else{
//.......if I want to come here,I must mock dependency0 and dependency1
doElse()
}
}

func (s *impl) needToPartialMocked() bool{
if xxxx() {
return s.dependency0,IsExisted();
}else{
return s.dependency1.IsExisted();
}
}

As commenting,if I can partial mock the method "needToPartialMocked()",set it return false directly,in some test case,lots of mocking stuff can be cut away.

@matryer
Copy link
Member

matryer commented Jan 28, 2014

I wouldn't use that pattern. And it turns out it isn't very easy to do at all. @tyleerb - any ideas?

@tylerstillwater
Copy link
Contributor

It may be easier to provide a way to create a "set" of mocks that can be applied in a single line.

On January 28, 2014 at 9:13:34 AM, Mat Ryer (notifications@github.com) wrote:

I wouldn't use that pattern. And it turns out it isn't very easy to do at all. @tyleerb - any ideas?


Reply to this email directly or view it on GitHub.

@matryer
Copy link
Member

matryer commented Jan 28, 2014

But first - I’d consider extracting the information into a new concept… if one thing uses itself, that’s just internals - which I am a fan of testing, but Go makes it hard. If you can pull it out into something else, i.e. the thing you’re testing has a pointer to the other thing - then you can easily mock that other thing.

On Jan 28, 2014, at 10:18 AM, Tyler notifications@github.com wrote:

It may be easier to provide a way to create a "set" of mocks that can be applied in a single line.

On January 28, 2014 at 9:13:34 AM, Mat Ryer (notifications@github.com) wrote:

I wouldn't use that pattern. And it turns out it isn't very easy to do at all. @tyleerb - any ideas?


Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants