Skip to content

Is it possible to implement partial mocking? #29

Closed
@AlexLuya

Description

@AlexLuya

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.

Activity

matryer

matryer commented on Jan 28, 2014

@matryer
Member

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

tylerstillwater

tylerstillwater commented on Jan 28, 2014

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

matryer commented on Jan 28, 2014

@matryer
Member

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tylerstillwater@matryer@AlexLuya

        Issue actions

          Is it possible to implement partial mocking? · Issue #29 · stretchr/testify