Testing and Debugging

2017-02-17  本文已影响0人  愁容_骑士

1. 设计程序时,目标为 defensive programming(防错型编程)

TESTING/VALIDATION
• Compare input/output pairs to specification
• “It’s not working!”
• “How can I break my program?”

DEBUGGING
• Study events leading upto an error
• “Why is it not working?”
• “How can I fix myprogram?

2. 测试开始前:

3. 准备测试:

4. 测试步骤

Paste_Image.png

5.测试处理:TESTING APPROACHES

  1. intuition about natural boundaries to the problem

def is_bigger(x, y):
""" Assumes x and y are ints
Returns True if y is less than x, else False """

 can you come up with some natural partitions?

2. if no natural partitions, might do **random testing**
>    -  probability that code is correct increases with more tests
>    - better options below

3. **black box testing**
• explore paths through specification
4. **glass box testing**
• explore paths through code

####GLASS BOX TESTING(黑盒测试)
- designed *without looking* at the code
- can be done by someone other than the implementer to
avoid some implementer biases
- testing can be reused if implementation changes
- paths through specification
• build test cases in different natural space partitions
• also consider boundary conditions (empty lists, singleton
list, large numbers, small numbers)

![Paste_Image.png](https://img.haomeiwen.com/i4585153/12368d5c40cba40c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

####GLASS BOX TESTING
-  use code directly to guide design of test cases
-  called path-complete if every potential path through code is tested at least once
- what are some drawbacks of this type of testing?
• can go through loops arbitrarily many times
• missing paths
-  guidelines
• branches
>exercise all parts of a conditional

 • for loops

 • while loop

![Paste_Image.png](https://img.haomeiwen.com/i4585153/67da29e53fc69ad3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

上一篇 下一篇

猜你喜欢

热点阅读