java - Mocking inter-method dependencies -


I have recently started using the mock object in my tests, but I am still very naive with them and How to use them in some cases uncertain, I am currently struggling to mimic inter-reliance dependence (method of method method A is an effect on the method), and should it also be joke (a mast structure In the spirit of using )?

Take a Java Iterator for example? To return the right values, it is very easy to copy the next () call, but how do I copy next (), depending on how many times () have been called? Currently I am using a list. As an interpreter I could not find any way to make a fake.

Is there a difference between Martin Fowler and Marks and Stubbs in the game? Should i write your ittermoke?

Also consider the following example. The method to examine the method is mockObject.setX () and later on mockObject.getX (). Is there any way that I can make such a fake (without writing your own), which will depend on the return value of getX to be passed to setx?

In general, I follow the advice of DJN above and establish expectations for both methods . But for the given example I probably will not use a duplicate, but instead I want to use the API to create an archive with the data I want and retrieve the Iterator from it. ( Arrays.asList (...). Iterator () ).

Edit: Re: Set / Receive What else are you doing with this object? If it is a value object (only gets / set) I did not want to make fun of it for a lot of effort to make a lot of effort if it is not easy to use the easy MAC:

  Import org.apache.commons.lang.mutable.MutableInt; Import org.easymock.IAnswer; Import org.junit.Test; Static org.easymock import. EasyMock. *; Public Square TestSet {@Test Public Zero TestSatagate () {Final MutableInt Value = New MutableInt (); GetSetId id = createMock (GetSetId.class); Id.setID (anyInt ()); Required Lists () And Enter (New IANS & lt; Object & gt; () {Reply to Override Public Object} Throwshell {Object Arguments} = Meet Content Agreement (); Value .SetView (integer) arguments [0]); Return tap;}}); Hope is (ID.getID) and reply (New Insver & lt; Integer> () (Reply to Override Public Integer) Throws throws {Return value. Tutorial ();}}); Recurrence (ID); Id.setID (int (Math.random (* * 100.0); Println (id.getID ()); Verify (id);}} GetSetId {public int getID (); Public Zero setID (int id );}  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -