What is Mocking

0 votes

What does Mocking mean in the terms of unit testing?   

Feb 8, 2022 in Others by Rahul
• 9,670 points
530 views

1 answer to this question.

0 votes

The meaning of the word refers to something made as an imitation. It is used mostly in unit testing. An object which is under test could have dependencies on other complex objects and in order to isolate the object behavior, the other objects have to be replaced by mocks which will eventually stimulate the behavior of the real objects. This would be useful if the real objects are not practically relevant to add into the unit test. In other words, the creation of objects which stimulate the behavior of real objects is defined as mocking.

The stub implements just about adequate behavior to permit the object under test to execute the given test. A mock is similar to a stub but the test will verify that the object under the test does call the mock as expected. To check if the mock was used correctly and verifying that is one of the parts of the test. To give you a better understanding of this, you could stub a given database only by using a simple in memory structure which will be used for storing records. Following which the object which is placed under the test can then read and also write records to the database stub which will allow it to execute the test which will test some behavior of the object which wouldn’t be related to the database.

Due to this, the database stub will only be included to allow the running of the test. You will have to mock the database in order to verify that the given object under test writes specific metrics to the database. The test finally takes assertions about how and what was written in the mock database. 
 

answered Feb 8, 2022 by Soham
• 9,700 points

Related Questions In Others

0 votes
1 answer

What is the difference between hadoop and google analytics ?

I will try and answer this as ...READ MORE

answered Aug 22, 2018 in Others by Frankie
• 9,830 points
1,296 views
+5 votes
6 answers

what is artificial neural network?

Machine Learning is a field of computer ...READ MORE

answered Dec 17, 2018 in Others by Raghumishra
• 240 points
2,166 views
+1 vote
1 answer

What is the difference between Dark Web and Deep Web?

The content that which you cannot find ...READ MORE

answered Feb 6, 2019 in Others by Priyaj
• 58,090 points
884 views
+1 vote
2 answers

What is the different between xml and json?

These are the differences:   It is JavaScript Object ...READ MORE

answered Feb 7, 2019 in Others by Junaid
977 views
0 votes
1 answer

Writing unit tests in Python: How do I start?

If you're brand new to using unittests, ...READ MORE

answered Sep 18, 2018 in Python by Priyaj
• 58,090 points
734 views
0 votes
1 answer
0 votes
1 answer

Mocking static methods with Mockito

@RunWith(PowerMockRunner.class) @PrepareForTest(DriverManager.class) public class Mocker { ...READ MORE

answered Dec 12, 2018 in Java by Daisy
• 8,120 points
6,977 views
0 votes
1 answer

How can I run test methods in specific order in JUnit4?

@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class SampleTest { ...READ MORE

answered Jan 7, 2019 in Java by Daisy
• 8,120 points
1,067 views
0 votes
1 answer

What is dependency injection?

According to James Shore, the term “Dependency ...READ MORE

answered Feb 8, 2022 in Others by Soham
• 9,700 points
441 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP