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.