What is the main difference between a stubs, a mock?

0 votes
58 views
Sanjay Goenka asked 06-Apr-2022 in troubleshooting by Sanjay Goenka

What is the main difference between a stubs, a mock?

1 Answer

0 votes
Hitesh Vohra answered 07-Apr-2022 by Hitesh Vohra
  • A stub interface simulates an actual object by having a small number of methods. It's a type of object that has pre-existing data and always returns the same value regardless of the input. Furthermore, we mostly employ it when we don't want the real object to respond.
  • The mock is an interface that we programme to compare the outputs from the tests to the expected outcomes. We frequently use third-party libraries such as Mockito and JMock to accomplish this. It's particularly useful when we're working with a large test suite and each test demands a different set of data.
  • Stubs offer input for the application under test, allowing the test to be run on something other than the application under test.
  • Mocks provide information to the test that helps it determine whether it should pass or fail.
  • A stub is for the application, while a mock is for the test


Read More: What is mean by software scope?