- Test-Driven Java Development(Second Edition)
- Alex Garcia Viktor Farcic
- 222字
- 2021-06-24 18:31:44
Mocking
In order for tests to run quickly and provide constant feedback, code needs to be organized in such a way that the methods, functions, and classes can be easily replaced with mocks and stubs. A common word for this type of replacements of the actual code is test double. The speed of execution can be severely affected with external dependencies; for example, our code might need to communicate with the database. By mocking external dependencies, we are able to increase that speed drastically. Whole unit test suite execution should be measured in minutes, if not seconds. Designing the code in a way that can be easily mocked and stubbed forces us to structure that code better by applying a separation of concerns.
More important than speed is the benefit of the removal of external factors. Setting up databases, web servers, external APIs, and other dependencies that our code might need, is both time consuming and unreliable. In many cases, those dependencies might not even be available. For example, we might need to create a code that communicates with a database and have someone else create a schema. Without mocks, we would need to wait until that schema is set.
With or without mocks, the code should be written in such a way that we can easily replace one dependency with another.
- Game Programming Using Qt Beginner's Guide
- 編寫高質量代碼:改善C程序代碼的125個建議
- Blockly創意趣味編程
- C語言從入門到精通(第4版)
- PhpStorm Cookbook
- Java Web開發詳解
- Java Web開發就該這樣學
- Python 3.7從入門到精通(視頻教學版)
- Natural Language Processing with Python Quick Start Guide
- Advanced Python Programming
- 虛擬現實:引領未來的人機交互革命
- Qt編程快速入門
- 匯編語言程序設計
- 區塊鏈原理、設計與應用
- CorelDRAW X6中文版應用教程(第二版)