Re: EasyMock and MVP architecture testing

2009-09-17 Thread Thomas Broyer



On 16 sep, 02:23, Ben benzhe...@gmail.com wrote:
 Thanks, Thomas. I will try it out and it seems that writing unit tests
 costs a lot of time.

It depends how many tests you write (racing for 100% code coverage is
counter productive); but in the end, it really *saves* you a lot of
time (prevents regressions, etc.) (investment cost vs. maintenance
cost)
I can tell you that because we have a project with absolutely *no*
automated test, and we regularly broke something while fixing another
or adding a new feature (this was also made far easier because we had
spaghetti code all around the place, and no clear specification to
start with)

Good literature can be found at: http://googletesting.blogspot.com/
(remember to read their TotT category ;-) )

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~--~~~~--~~--~--~---



Re: EasyMock and MVP architecture testing

2009-09-15 Thread Ben

Thanks, Thomas. I will try it out and it seems that writing unit tests
costs a lot of time.

-Ben

On Sep 10, 5:28 am, Thomas Broyer t.bro...@gmail.com wrote:
 On 10 sep, 00:30, Ben benzhe...@gmail.com wrote:

  Hi, I am using MVP architecture for my application, but I am trying to
  use EasyMock to provide mock objects to test all my presenters. I have
  a question about testing event handlers from GWT such as ClickHandler.
  Does anyone try to use EasyMock to test click event? Or I should write
  my own mock event and mock handler like it is mentioned in GWT blog.

 Here's an adapted excerpt from my code:

 MyPresenter.Display view = createMock(MyPresenter.Display.class);
 HasClickHandlers button = createMock(HasClickHandlers.class);
 expect(view.getSomeButton()).andStubReturn(button);

 CaptureClickHandler clickHandler = new CaptureClickHandler();
 HandlerRegistration clickRegistration = createNiceMock
 (HandlerRegistration.class);
 expect(button.addClickHandler(capture(clickHandler))).andReturn
 (clickRegistration);

 replay(view, button, clickRegistration);

 new MyPresenter(view);

 clickHandler.getValue().onClick(null);

 verify(view, button, clickRegistration);

 Here, I'm expecting a single ClickHandler to be registered on the
 view's getSomeButton() (afaict, from memory, the sample hand-written
 mock from Ray's preso behaves the same), and one that doesn't make
 use of the ClickEvent (if that's not your case, you can use
 org.easymock.classextension.createMock(ClickEvent.class) and some
 expect(clickEvent.getSource()).andStubReturn(button).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~--~~~~--~~--~--~---



Re: EasyMock and MVP architecture testing

2009-09-10 Thread Thomas Broyer


On 10 sep, 00:30, Ben benzhe...@gmail.com wrote:
 Hi, I am using MVP architecture for my application, but I am trying to
 use EasyMock to provide mock objects to test all my presenters. I have
 a question about testing event handlers from GWT such as ClickHandler.
 Does anyone try to use EasyMock to test click event? Or I should write
 my own mock event and mock handler like it is mentioned in GWT blog.

Here's an adapted excerpt from my code:

MyPresenter.Display view = createMock(MyPresenter.Display.class);
HasClickHandlers button = createMock(HasClickHandlers.class);
expect(view.getSomeButton()).andStubReturn(button);

CaptureClickHandler clickHandler = new CaptureClickHandler();
HandlerRegistration clickRegistration = createNiceMock
(HandlerRegistration.class);
expect(button.addClickHandler(capture(clickHandler))).andReturn
(clickRegistration);

replay(view, button, clickRegistration);

new MyPresenter(view);

clickHandler.getValue().onClick(null);

verify(view, button, clickRegistration);


Here, I'm expecting a single ClickHandler to be registered on the
view's getSomeButton() (afaict, from memory, the sample hand-written
mock from Ray's preso behaves the same), and one that doesn't make
use of the ClickEvent (if that's not your case, you can use
org.easymock.classextension.createMock(ClickEvent.class) and some
expect(clickEvent.getSource()).andStubReturn(button).


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~--~~~~--~~--~--~---