rails测试很重要
蔡源茂 | 创建:2018-05-30 | 最后更新:2018-06-04 | 1444次阅读
2018-05-30 这是目前本站的代码统计,测试覆盖量太少,导致改动原有功能的时候,很容易引入bug
2018-05-31目前测试已经覆盖user、session、article三个控制器,开发测试代码比为1:0.5。发现bug一个
caiyuanmao@caiyuanmao:~/blog$ rails stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers | 474 | 371 | 10 | 53 | 5 | 5 |
| Helpers | 82 | 77 | 0 | 7 | 0 | 9 |
| Jobs | 2 | 2 | 1 | 0 | 0 | 0 |
| Models | 148 | 123 | 7 | 18 | 2 | 4 |
| Mailers | 4 | 4 | 1 | 0 | 0 | 0 |
| Channels | 8 | 8 | 2 | 0 | 0 | 0 |
| JavaScripts | 209 | 142 | 0 | 26 | 0 | 3 |
| Libraries | 127 | 107 | 4 | 6 | 1 | 15 |
| Controller tests | 531 | 355 | 6 | 29 | 4 | 10 |
| Helper tests | 0 | 0 | 0 | 0 | 0 | 0 |
| Model tests | 35 | 15 | 5 | 0 | 0 | 0 |
| Mailer tests | 0 | 0 | 0 | 0 | 0 | 0 |
| Integration tests | 0 | 0 | 0 | 0 | 0 | 0 |
| System tests | 18 | 6 | 2 | 0 | 0 | 0 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total | 1638 | 1210 | 38 | 139 | 3 | 6 |
+----------------------+--------+--------+---------+---------+-----+-------+
Code LOC: 834 Test LOC: 376 Code to Test Ratio: 1:0.5
2018-06-04 很难想象2k多一点的代码可以实现一个个人博客,还包含了测试。rails 你很棒!
caiyuanmao@caiyuanmao:~/blog$ rails stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers | 509 | 402 | 11 | 57 | 5 | 5 |
| Helpers | 84 | 79 | 0 | 7 | 0 | 9 |
| Jobs | 2 | 2 | 1 | 0 | 0 | 0 |
| Models | 183 | 153 | 8 | 23 | 2 | 4 |
| Mailers | 4 | 4 | 1 | 0 | 0 | 0 |
| Channels | 8 | 8 | 2 | 0 | 0 | 0 |
| JavaScripts | 212 | 142 | 0 | 26 | 0 | 3 |
| Libraries | 127 | 107 | 4 | 6 | 1 | 15 |
| Controller tests | 993 | 751 | 8 | 59 | 7 | 10 |
| Helper tests | 0 | 0 | 0 | 0 | 0 | 0 |
| Model tests | 42 | 18 | 6 | 0 | 0 | 0 |
| Mailer tests | 0 | 0 | 0 | 0 | 0 | 0 |
| Integration tests | 0 | 0 | 0 | 0 | 0 | 0 |
| System tests | 18 | 6 | 2 | 0 | 0 | 0 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total | 2182 | 1672 | 43 | 178 | 4 | 7 |
+----------------------+--------+--------+---------+---------+-----+-------+
Code LOC: 897 Test LOC: 775 Code to Test Ratio: 1:0.9