Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 987457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:28:43+00:00 2026-05-16T05:28:43+00:00

I’m interested in using the right mocking framework for my GWT app. It’s my

  • 0

I’m interested in using the right mocking framework for my GWT app. It’s my understanding that Mockito, EasyMock, and jMock are some of the most popular for Java. Could someone list pros/cons for the mocking framework that they are most familiar with as it relates to GWT to help fellow GWT testing noobs like myself?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:28:43+00:00Added an answer on May 16, 2026 at 5:28 am

    For the server side testing (RPC services) you can use any mocking framework you wish. spring-test library might be useful for mocking HttpRequest, HttpSession, and other classes of servlet api. Still you might have problems with testing classes extending RemoteServiceServlet, as they require properly encoded request. Here is interesting project which solves this problem:

    http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/

    When it comes to testing of client side GWT code (the part which is compiled into Java Script), you can extend GWTTestCase. However due to limited emulation of JRE library, lack of reflection API in particular, it would be impossible to use any mocking framework. What is more, GWTTestCase runtime is very slow, and for this reason consider as a base for integration testing rather than unit testing.

    It is possible to create unit tests for GWT client code if GWT application follows Model View Presenter pattern. Assuming we are testing so called “Presenter” (logic) we can mock so called “Display” with any mocking framework. Here is example unit test using Mockito:

    import static org.mockito.BDDMockito.*;
    import org.junit.Test;
    import com.google.gwt.user.client.ui.HasText;
    
    public class ResultPresenterTest {
    
        @Test
        public void shouldSetItWorksResultText() {
            // given
            ResultPresenter.Display display = mock(ResultPresenter.Display.class);
            MockButton button = new MockButton();
            HasText label = mock(HasText.class);
            given(display.getShowResultButton()).willReturn(button);
            given(display.getResultLabel()).willReturn(label);
            ResultPresenter presenter = new ResultPresenter();
            presenter.bind(display);
    
            // when
            button.click();
    
            // then
            verify(label).setText("It works");
        }
    
    }
    

    Here is the presenter:

    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.event.dom.client.HasClickHandlers;
    import com.google.gwt.user.client.ui.HasText;
    
    public class ResultPresenter {
    
        private Display display;
    
        public interface Display {
            HasClickHandlers getShowResultButton();
            HasText getResultLabel();
        }
    
        public void bind(final Display display) {
            this.display = display;
            display.getShowResultButton().addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    showResult();
                }
            });
        }
    
        public void showResult() {
            display.getResultLabel().setText("It works");
        }
    
    }
    

    And here is small helper class:

    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.event.dom.client.HasClickHandlers;
    import com.google.gwt.event.shared.GwtEvent;
    import com.google.gwt.event.shared.HandlerManager;
    import com.google.gwt.event.shared.HandlerRegistration;
    
    public class MockButton implements HasClickHandlers {
    
        private HandlerManager handlerManager = new HandlerManager(this);
    
        public void click() {
            handlerManager.fireEvent(new ClickEvent() {
            });
        }
    
        @Override
        public HandlerRegistration addClickHandler(ClickHandler handler) {
            return handlerManager.addHandler(ClickEvent.getType(), handler);
        }
    
        @Override
        public void fireEvent(GwtEvent<?> event) {
            handlerManager.fireEvent(event);
        }
    
    }
    

    It would make sense to call presenter.showResult() in ‘when’ section instead of button.click(), however as you can see mocking of event circulation is also possible.

    Google GIN might be very useful, as it allows to bind different instances depending on runtime/test context. On non-GWTTestCase presenter test GIN can be replaced with Guice.

    The com.google.gwt.junit.GWTMockUtilities might be also very useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.