官术网_书友最值得收藏!

Motivation for testing

"Things that are impossible just take longer."                                                                                                                                                                                                  -  Ian Hickson

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!

主站蜘蛛池模板: 固镇县| 渭源县| 隆林| 樟树市| 贺兰县| 兖州市| 翁牛特旗| 镶黄旗| 徐州市| 洛阳市| 甘洛县| 崇信县| 荃湾区| 太保市| 嘉峪关市| 天水市| 安西县| 万山特区| 桂阳县| 阳西县| 望江县| 抚远县| 随州市| 峡江县| 山东省| 吕梁市| 滨州市| 苏尼特左旗| 台湾省| 青冈县| 沈丘县| 昭通市| 明溪县| 达尔| 嘉禾县| 佛学| 永顺县| 康保县| 盘山县| 花垣县| 老河口市|