Mockito: How to make a method return an argument that was passed to it
Consider a method signature like: public String myFunction(String abc); Can Mockito help return the same string that the method received? ...
Consider a method signature like: public String myFunction(String abc); Can Mockito help return the same string that the method received? ...
At my day job I've been spoiled with Mockito's never() verification, which can confirm that a mock method is never called. Is there some way to accomplish the same thing using Objective-C and OCMock? I've been using the code below, which works but it feels like a hack. I'm hoping there's a better way... - (void)testSomeMethodIsNeverCal...
I am currently developing an android app in eclipse using: One project for the app One project for the tests (Instrumentation and Pojo tests) In the test project, I am importing the mockito library for standard POJO testing. However, when I import the library, the compilation time skyrockets from 1 second to about 30 seconds in eclip...
I'm trying to unit test a method which processes javax.mail.Message instances. I am writing a converter to change emails which arrive in different formats and are then converted into a consistent internal format (MyMessage). This conversion will usually depend on the from-address or reply-address of the email, and the parts of the emai...
One way of thinking about this is: if we care about the Design of the code then Easymock is the better choice as it gives feedback to you by its concept of expectations If we care about the maintainability of tests( easier to read,write and having less brittle tests which are not affected much by change), then Mockito seems a better choi...
Mockito api provides method: Mockito.verifyNoMoreInteractions(someMock); but is it possible in Mockito to declare that I don't want more interactions with a given mock with the exceptions of interactions with its getter methods? The simple scenario is the one in which I test that sut changes only certain properties of a given mock a...
I have a method that I am trying to unit test. This method takes a parameter as an ArrayList and does things with it. The mock I am trying to define is: ArrayList<String> mocked = mock(ArrayList.class); which gives a [unchecked] unchecked conversion" warning. ArrayList<String> mocked = mock(ArrayList<String>.class); gives me an...
I suspect this isn't possible as the anonymous inner class is private. Can I verify that the method was called without worrying about the argument? I'm tying to test this: http://bsnyderblog.blogspot.com/2010/02/using-spring-jmstemplate-to-send-jms.html With something like: verify(jmsTemplate, times(1)).send(); But send() needs an a...
This comparison shows, that JMockit has several advantages over other frameworks. Are there also any advantages that one of the others (JMock, EasyMock, Mockito, Unitils, PowerMock + Mockito/EasyMock) has over JMockit? ...
Hello, i dunno if the question is already ask, but i couldn't find it... i'm searching a way to mock my view in order to test my presenter ? i try to use mockito for the view, and set it in the presenter, but in result in presenter, when i call presenter.getDisplay() (the getter for the view) all of my widget is null ? as i believe it's...
Can I use Mockito to capture what was passed to the HttpServletResponse#sendError() method? I can't figure out how to do that. ...
Hello people. When I put a "VerificationModeFactory.times(2)" in test before, when I run all tests of the class appears this exception: org.mockito.exceptions.verification.WantedButNotInvoked: Wanted but not invoked: serviceService.getServices(); If I run each test separately or remove "VerificationModeFactory.times(2)" all works. It...
Hi there, recently I made the switch to Mockito framework and am very happy with it (see also blog-post). The switch from easymock to Mockito was very straightforward and I managed to make the tests down compatible (i.e. test cases behave the same). Do you see real reasons or shootout criteria to prefer easymock over Mockito? So far of...
When i create a mock object of say class Employee. It doesnt call the constructor of Employee object. I know internally Mockito uses CGLIb and reflection, creates a proxy class that extends the class to mock. If it doesnt call the constructor of employee how is the mock instance of employee class created ? ...
I've got JUnit tests that run just fine. Added Mockito to my build and I try to put a breakpoint in my JUnit test that uses Mockito to mock out some of the public methods. When I try to run the debugger on the class, I get the error "unable to install breakpoint in XXX due to missing line number attributes. Modify compiler options to g...
I am trying to mock the following call: s.socket().bind(new InetSocketAddress(serverIPAddress_, serverPort_), 0); so I can test what the rest of the code does when this fails in predictable ways. I use this in my test case: ServerSocketChannel ssc = mock(ServerSocketChannel.class); when(ServerSocketChannel.open()).thenReturn(ssc); do...
Is it posible to create a partial mock using mockito-flex? ...
Hello, I'm having a problem with ArgumentCaptor not being able to record the arguments when calling the same method a number of times. Basically this does not seem to work: List<Dummy> mList = mock(List.class); Dummy dummy = new Dummy(); when(mList.get(anyInt())).thenReturn(dummy); Dummy d = mList.get(12); d.setName("John"); mList....
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. ...
Hi, actually im doing some tests with Mockito. I have the following class: class BaseService{ public void save(){...} } public Childservice extends BaseService{ public void save(){ //some codes super.save() } } I want to mock only the second call (super.save) of the ChildService & do nothing so the test is successfull....