Software_programming_architecture_unitTest

2019-12-02


------------- Pragmatic Unit Testing ----------------

1. General Principies: 一般原则
1) Test anything that might break. 测试任何可能失败的地方
2) Test everything that does break. 测试任何已经失败的地方
3) New code is guilty until proven innocent 对于新加的代码,在被证明正确之前,都可能是有问题的。
4) Write at least as Test code as production code 至少编写和产品代码一样多的测试代码
5) Run local tests with each compile 针对每次编译都做局部测试
6) Run all tests before check-in repository 签入代码之前做全局测试。

2 Question to Ask 要回答的问题
1) If the code run correctly, how would i know? 我如何知道代码运行是否正确呢。
2) How am i going to test this 我要如何对它进行测试。
3) What else can go wrong ? 还有哪些方面可能会发生错误。
4) Could this same kind of problem happen anywhere else? 这个问题是否会在其他的地方出现呢。

3 What to Test: Use your RIGHT-BICEP
1) Are the result right 结果是否正确
2) Are all the boundary conditions CORRECT? 边界条件是否正确
3) Can you check inverse relationships? 是否可以检查反向关联
4) Can you cross-check results using other means 是否可以使用其他方法来跨检查结果
5) Can you force error-condition to happen? 错误条件是否可以重现
6) Are performance characteristics within bounds? 性能方面是否满足条件

4 Good Tests are A TRIP
1) Automatic 自动的
2) Through 全面的
3) Repeatable 可重复的
4) Independent 独立的
5) Professional 专业的

5 CORRECT boundary conditions

1) Confromance - Does the value conform to an expected format? 一致性 值是否符合预期的格式
2) Ordering - Is the set of values ordered or unordered as appropriate? 有序性 一组值是有序的,还是无序的
3) Ranges - Is the value reasonable minimum and maximum values? 区间性 值是否在一个合理的最大值和最小值的范围之内
4) Reference - Does the code reference external that 引用,耦合性 代码是否引用了一些不受代码本身直接控制的外部因素
isn`t under direct control of the code itself?
5) Exitence - Does the value exist?
(e.g.,is non-null? non-zero? present in a set, etc.) 存在性 值是否存在,非null, 非零,包含于某个集合等
6) Cordinality - Are there exactly enought values? 基数性 是否恰好有足够的值
7) Time(absolute and relative) - Is everything happening in order? 时间性 所有的时请是否都是按顺序发生的?是否在正确的事件,是否及时?
At the right order? At time?

 


 2020-05-09

单元测试

之 随机性测试:

对数据集进行随机取值验证,  例如在 list  中  (int) (Math.random() * list.size()   随机获取一个 index

然后进行验证.

1 List<String> total =  Arrays.asList("V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9",
2                 "VK", "VL", "VM", "VT", "VU", "VV", "VP", "VQ", "VR", "VX", "VY", "VZ",
3                 "H8", "H9");
4 
5         for(int i = 0 ; i < 100; i++){
6             int idx = (int)(Math.random()*total.size());
7             assertEquals(true, validation_19.validate("condenser", total.get(idx)));
8         }

 



 

 

 

posted @ 2019-12-02 10:59  君子之行  阅读(1)  评论(0编辑  收藏  举报