keeganwitt / gmock

Automatically exported from code.google.com/p/gmock
6 stars 2 forks source link

Play forever #129

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I would like to use GMock in UI tests, mocking the service layer of an 
application.  It would be helpful if I could call play() without a closure.

Original issue reported on code.google.com by mrsqueez...@gmail.com on 24 Apr 2012 at 1:26

GoogleCodeExporter commented 8 years ago
I do not quite understand what you mean. Can you give a scenario or an example 
to show what you want to use Gmock for?

Original comment by JohnnyJianHY on 24 Apr 2012 at 1:33

GoogleCodeExporter commented 8 years ago
Thanks for the quick response.  I would like to call play() and not expect any 
validation, just some mocks that will return what I have specified forever.  
We're planning to mock out some external services for UI tests because the 
external services do not return data deterministically.  Unfortunately, because 
Grails is running the application, I don't know how to surround the execution 
of the app with a "play { }"  We could write some mock implementations of those 
classes, but gmock seemed simpler.  I've used Mockito for this when I've 
deveolped in Java, but it doesn't work in Groovy.  We've had a lot of success 
with gmock and would like to use it for this too.

Original comment by mrsqueez...@gmail.com on 24 Apr 2012 at 2:26

GoogleCodeExporter commented 8 years ago
I don't understand, do you mean your test will continue after the test case? Or 
your test is not an automatic test?

Original comment by JohnnyJianHY on 24 Apr 2012 at 2:41

GoogleCodeExporter commented 8 years ago
The app isn't aware that it is being tested.  The Grails app will start with 
some mocked resources.  Then, an automated Selenium test will run, accessing 
the app's UI.  We'd just be using gmock for its "when this, then that" 
abilities, no validation.

I would put some sample code here, but there are so many files and it's so 
Grails-specific that it seems easier to just describe it.

Original comment by mrsqueez...@gmail.com on 24 Apr 2012 at 3:06

GoogleCodeExporter commented 8 years ago
I don't think you should do it with a mocking framework in this case, even 
though you can use Mockito in Java, I still don't think it is the right way.

Original comment by JohnnyJianHY on 24 Apr 2012 at 3:29

GoogleCodeExporter commented 8 years ago
Thanks for taking the time to listen.  Great work on gmock!

What I'll be doing instead is writing a class that returns certain values based 
on certain input values, which still sounds a lot like mocking to me.  I 
suppose I'll see.

Original comment by mrsqueez...@gmail.com on 24 Apr 2012 at 7:35

GoogleCodeExporter commented 8 years ago
One of the most important features of mocking frameworks is, you can define 
different behaviors for different test cases.

IMO, in this scenario, you should do some MOP, that is, change the behaviors of 
the services via metaclass, because you need to define the behaviors only once 
and don't need to rollback.

Original comment by JohnnyJianHY on 25 Apr 2012 at 1:47