Week 2 – CST438 Software Engineering

In lab 1 on Junit you used a Mock.  In your own words describe what a Mock is and why it is useful in unit testing. 

Mocks are objects or behaviors used as stand ins for other components during a Junit test. Mocks are useful in unit testing because they allow us to simulate the normal function of a component by providing predefined responses to method calls rather than performing the actual logic or operation. When using mocks, you eliminate the unpredictability that comes with interactions with other components.

The goal with unit testing is to isolate the unit being tested. With mocks you can generate tests that are controlled and predictable. Mocks allow us to avoid real interactions with outside components which can potentially modify data. This eliminates the need to reset data back to its original state after the test is completed.

Another useful attribute of mocks in unit testing is that it allows the unit test to be dependable and fast. For example, instead of having the component make network calls or query a database, you can use mocks to avoid these slow and unreliable interactions. This will speed up the execution time of the unit tests.

All these attributes of a mock allow Junit testing to follow the FIRST acronym Fast, Independent, Repeatable, Self-checking, and Timely.


Comments

Popular posts from this blog