Loading ...
Sorry, an error occurred while loading the content.
 

Re: [easymock] Feedback anyone???

Expand Messages
  • Tammo Freese
    Hello Henry, ... if you typically have situations where you would like to use more than one mock, you may use an IMocksControl: public void setup() {
    Message 1 of 3 , Jul 24, 2008
      Hello Henry,


      Am 24.07.2008 um 03:17 schrieb Carlus Henry:
      > More and more I am finding myself using a certain pattern when it
      > comes to using EasyMock, and I am wondering if this is a best
      > practice, or if there is an easier way available that I don't know
      > of, in order to get this to work.
      >
      > For example, if I am testing an Object A that collaborates with
      > Interfaces B, C, and D, typically I will declare them as class
      > variables. I also declare an Object[] called mockArray.
      > Afterwards, my setup method looks like this
      >
      > public void setup() {
      > a = createMock(IA.class);
      > b = createMock(IB.class);
      > c = createMock(IC.class);
      >
      > mockArray = new Object[]{a, b, c};
      > }
      >
      > Then I declare the following helper methods:
      >
      > verifyAll(){ verify(mockArray);}
      > replayAll() {replay(mockArray);}
      >
      > This allows me to make sure that all of my mocks are put into
      > replay mode and all of them are verified after the code that I am
      > testing is executed.
      >
      > Is there an easier way of doing this? What are your thoughts on
      > this approach?


      if you typically have situations where you would like to use more
      than one mock,
      you may use an IMocksControl:

      public void setup() {
      mocksControl = createControl();
      a = mocksControl.createMock(IA.class);
      b = mocksControl.createMock(IB.class);
      c = mocksControl.createMock(IC.class);
      }

      Then,

      mocksControl.replay();

      will switch all the mocks to replay mode, and

      mocksControl.verify();

      will verify them all.


      Hope that helps,

      Tammo
    Your message has been successfully submitted and would be delivered to recipients shortly.