What is Mocking

0 votes

What does Mocking mean in the terms of unit testing?   

Feb 8 in Others by Rahul
• 8,980 points
25 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 by Soham
• 8,730 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
716 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
732 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,060 points
354 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
333 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,060 points
362 views
0 votes
2 answers

How can I make Python's UnitTest Framework fail if an exception is raised by any thread?

http://www.drdobbs.com/testing/testing-for-failures-with-python/240169387 Try reading the above document. I ...READ MORE

answered Mar 9, 2019 in Python by anonymous
5,646 views
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
5,578 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
590 views
0 votes
1 answer

What is dependency injection?

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

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