KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I know how I use these terms, but I'm wondering if there are accepted definitions for faking , mocking , and stubbing for unit tests? How do you define these for your tests? Describe situations where you might use each. Here is how I use them: Fake : a class that implements an interface but contains fixed data and no logic. Simply returns "good" or "bad" data depending on the implementation. Mock : a class that implements an interface and allows the ability to dynamically set the values to return/exceptions to throw from particular methods and provides the ability to check if particular methods have been called/not called. Stub : Like a mock class, except that it doesn't provide the ability to verify that methods have been called/not called. Generation of each: Mocks and Stubs can be hand-generated or generated by a mocking framework. Fake classes are generated by hand. Using them as follows: Mocks primarily to verify interactions between my class and dependent classes. Stubs once I have verified the interactions and am testing alternate paths through my code. Fake classes primarily to abstract out data dependencies or when mocks/stubs are too tedious to set up each time.
Tags (comma-separated)
Save Edits
Cancel