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 hook the mock lib of testify into ginkgo? #17

Closed
AlexLuya opened this issue Nov 22, 2013 · 6 comments
Closed

Is it possible to hook the mock lib of testify into ginkgo? #17

AlexLuya opened this issue Nov 22, 2013 · 6 comments

Comments

@AlexLuya
Copy link

I think the mocking style of testify(https://github.com/stretchr/testify) is more nature than gomock,is it possible to hook it's mock lib into ginkgo?

@onsi
Copy link
Owner

onsi commented Nov 22, 2013

It looks like testify uses (*testing.T) directly instead of an interface (which gomock does). Ginkgo can provide such frameworks with a Fail function that one can wrap in such a way to satisfy most interfaces (this is how we support go mock), but *testing.T refers to a concrete type and passing in the testing.T for the test that Ginkgo runs in would cause the entire suite to fail should one of your mock assertions fail...

So: step one would be to get a pull request into testify that replaces *testing.T with an interface (not hard from an implementation perspective, but it does add a layer of obfuscation into testify?) After that I should be able to cook up a testify module much like the go mock module.

@AlexLuya
Copy link
Author

I have tried several mocking frameworks,such as gomock,mock of testify, mogo(https://github.com/gcurtis/mogo) that is quite like testify mock,and mock4go (https://github.com/jvshahid/mock4go).I found mock4go's approach is quite concise.So is it possible to integrate it to ginkgo?The last updates of mock4go has happened 7 month ago,but it doesn't matter,I will contact author,if he is busy or wants to quit, I can provide some help.

@onsi
Copy link
Owner

onsi commented Dec 23, 2013

Hey @AlexLuya:

mogo looks like a slightly cleaner implementation than testify and would fit right into Ginkgo. One could even right a simple Gomega matcher to wrap calling the Verify method and asserting there is no error into a one-liner.

mock4go seems much more elaborate. in principal It Could Just Work... though it sounds like you have to run tests using mock4go which, I imagine, does the instrumentation then calls down to go test -- I don't know if it'll let you pass flags down to go test so you might lose some of ginkgo's more advanced command line stuff.

Did you try using mock4go in a ginkgo suite? If you give it a try and it doesn't work I'd be happy to take a look.

If you want my opinion:

I generally prefer avoiding mocks/stubs entirely by writing my own fakes and injecting them into my objects under test. mogo sounds like a simple enough wrapper that allows you to write fakes with (a little) less code. IMHO mock4go goes a bit too far by instrumenting your production code. it probably doesn't break things.... but it is amending your code under the hood!

@AlexLuya
Copy link
Author

I agree with this:

"mock4go goes a bit too far by instrumenting your production code. it
probably /doesn't/ break things.... but it /is/ amending your code under

the hood!"

And have report to author: jvshahid/mock4go#2

I will to try mogo with ginko.

On 12/24/2013 04:18 AM, Onsi Fakhouri wrote:

Hey @AlexLuya https://github.com/AlexLuya:

mogo looks like a slightly cleaner implementation than testify and
would fit right into Ginkgo. One could even right a simple Gomega
matcher to wrap calling the |Verify| method and asserting there is no
error into a one-liner.

mock4go seems much more elaborate. in principal It Could Just Work...
though it sounds like you have to run tests using |mock4go| which, I
imagine, does the instrumentation then calls down to |go test| -- I
don't know if it'll let you pass flags down to |go test| so you might
lose some of |ginkgo|'s more advanced command line stuff.

Did you try using |mock4go| in a ginkgo suite? If you give it a try
and it doesn't work I'd be happy to take a look.

If you want my opinion:

I generally prefer avoiding mocks/stubs entirely by writing my own
fakes and injecting them into my objects under test. mogo sounds like
a simple enough wrapper that allows you to write fakes with (a little)
less code. IMHO mock4go goes a bit too far by instrumenting your
production code. it probably /doesn't/ break things.... but it /is/
amending your code under the hood!


Reply to this email directly or view it on GitHub
#17 (comment).

@onsi
Copy link
Owner

onsi commented Jan 30, 2014

This is now possible!

See
http://onsi.github.io/ginkgo/#using_other_matcher_libraries

for an example of using testify with Ginkgo.

@onsi onsi closed this as completed Jan 30, 2014
@wolfgangmeyers
Copy link

@onsi correction on the link - http://onsi.github.io/ginkgo/#using-other-matcher-libraries

xjh1996 pushed a commit to xjh1996/ginkgo that referenced this issue Jan 12, 2021
feature: add tenant to request
xjh1996 pushed a commit to xjh1996/ginkgo that referenced this issue Jan 12, 2021
* bugfix: loadconfig (onsi#17)

feature: add tenant to request

* WIP:add auth demo
xjh1996 pushed a commit to xjh1996/ginkgo that referenced this issue Jan 12, 2021
* bugfix: loadconfig (onsi#17)

feature: add tenant to request

* WIP:add auth demo

* optimize case structure
xjh1996 pushed a commit to xjh1996/ginkgo that referenced this issue Jan 12, 2021
* bugfix: loadconfig (onsi#17)

feature: add tenant to request

* WIP:add auth demo

* bugfix: 修正API
xjh1996 pushed a commit to xjh1996/ginkgo that referenced this issue Jan 12, 2021
* bugfix: loadconfig (onsi#17)

feature: add tenant to request

* WIP:add auth demo

* add cargo preset
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