Top "Mocking" questions

Mocking and faking are ways to isolate code or components to ensure that unit tests run against the testable unit of code only without actually utilizing other components or dependencies of an application.

How to mock void methods with Mockito

How to mock methods with void return type? I implemented an observer pattern but I can't mock it with Mockito …

java unit-testing mocking mockito void
Mocking static methods with Mockito

I've written a factory to produce java.sql.Connection objects: public class MySQLDatabaseConnectionFactory implements DatabaseConnectionFactory { @Override public Connection getConnection() { try { …

java unit-testing static mocking mockito
Use Mockito to mock some methods but not others

Is there any way, using Mockito, to mock some methods in a class, but not others? For example, in this (…

java mocking mockito
What's the difference between a mock & stub?

I've read various articles about mocking vs stubbing in testing, including Martin Fowler's Mocks Aren't Stubs, but still don't understand …

testing mocking stub
Using Mockito's generic "any()" method

I have an interface with a method that expects an array of Foo: public interface IBar { void doStuff(Foo[] arr); } …

java unit-testing mocking mockito
How to check String in response body with mockMvc

I have simple integration test @Test public void shouldReturnErrorMessageToAdminWhenCreatingUserWithUsedUserName() throws Exception { mockMvc.perform(post("/api/users").header("Authorization", base64ForTestUser).…

java spring mocking spring-test-mvc
Mockito test a void method throws an exception

I have a method with a void return type. It can also throw a number of exceptions so I'd like …

java exception mocking mockito
Difference between @Mock and @InjectMocks

What is the difference between @Mock and @InjectMocks in Mockito framework?

java unit-testing mocking mockito
Can Mockito capture arguments of a method called multiple times?

I have a method that gets called twice, and I want to capture the argument of the second method call. …

java unit-testing mocking mockito
Mocking member variables of a class using Mockito

I am a newbie to development and to unit tests in particular . I guess my requirement is pretty simple, but …

java mocking mockito