- Mastering Rust
- Rahul Sharma Vesa Kaihlavirta
- 444字
- 2021-07-02 13:35:23
Motivation for testing
Software systems are like machines with small cogs and gears. If any of the individual gears malfunctions, the machine as a whole is most likely to behave in an unreliable manner. In software, the individual gears are functions, modules, or any libraries that you use. Functional testing of the individual components of a software system is an effective and practical way of maintaining high quality code. It doesn't prove that bugs don't exist, but it helps in building confidence when deploying the code to production and maintaining the sanity of the code base when the project is to be maintained for a long time. Furthermore, large-scale refactoring in software is hard to do without unit tests. The benefits of the smart and balanced use of unit testing in software are profound. During the implementation phase, a well-written unit test becomes an informal specification for components of the software. In the maintenance phase, the existing unit tests serve as a harness against regressions in the code base, encouraging an immediate fix. In compiled languages like Rust, this gets even better as the refactors involved (if any) for regressions from unit tests are more guided due to helpful error diagnostics from the compiler.
Another good side effect of unit tests is that they encourage the programmer to write modular code that is mostly dependent on the input parameters, that is, stateless functions. It moves the programmer away from writing code that depends on a global mutable state. Writing tests that depend on a global mutable state are hard to write. Moreover, the act of simply thinking about writing tests for a piece of code helps the programmer figure out silly mistakes in their implementation. They also act as very good documentation for any newcomer trying to understand how different parts of the code base interact with each other.
The takeaway is that tests are indispensable for any software project. Now, let's look at how we can write tests in Rust, starting by learning about organizing tests!
- Docker技術入門與實戰(第3版)
- Python語言程序設計
- 云原生Spring實戰
- Java程序員面試算法寶典
- Full-Stack Vue.js 2 and Laravel 5
- AppInventor實踐教程:Android智能應用開發前傳
- 從零開始學C語言
- Android Development Tools for Eclipse
- 從零開始學Selenium自動化測試:基于Python:視頻教學版
- Penetration Testing with the Bash shell
- Learning Perforce SCM
- 亮劍C#項目開發案例導航
- Python GUI設計:tkinter菜鳥編程
- Visual FoxPro程序設計
- 騰訊游戲開發精粹Ⅲ