[关闭]
@smilence 2013-10-24T22:58:51.000000Z 字数 1340 阅读 2868

Chapter 9 Testing


"The Rules"


1.Testing a Real World Object or a Software or a Function
三者并无本质的差别,问题的意义均取决于:测试对象在不同的输入下,能否实现预计的功能。 一般总是可以考虑以下 Test Cases下测试对象的"效果":(1) 不同类型的Normal cases (2) Extreme cases ( 边界条件,或极端情况如不同用户或thread频繁access/update ) (3) Invalid case。

e.g.1 How would you test a paperclip? (CtCI example)
e.g.2 Provide test cases for function sort( int array[] ).(CtCI example)
e.g.3 Test the following method in a chess game: bool canMoveTo( int x, int y).(CtCI:12.3)
e.g.4 How would you load test a webpage without using any test tools?( CtCI: 12.4)
e.g.5 How would you test a pen?( CtCI: 12.5)
e.g.6 How would you test an ATM in a distributed banking system? (CtCI:12.6)

2.Troubleshooting
总是可以遍历测试对象由生成到运行的call flow,观察每一步的"变量"及其dependency,确定可能出现问题的步骤。注意问题的起点与终点。

e.g.1 Troubleshooting for a web browser crash.( CtCI example )
e.g.2 Find the mistake(s) in the following code: (CtCI: 12.1)

  1. unsigned int i;
  2. for( i = 100; i >= 0; --i )
  3. printf( "%d\n", i );

e.g.3 Given the source to an application, you find it never crashes in the same place.The application is single threaded, and uses only the C standard library.What programming errors could cause the crash?How would you test each one? ( CtCI: 12.2)

3.GNU Debugger Commands
(1) Compile with GDB support: gcc -g prog.c -o prog.x;
(2) Start debugging: gdb prog.x , (gdb) run;
(3) Handle breakpoints: (gdb) break prog.c: 6 or (gdb) break my_func; if, continue, step, next; delete;
(4) Watch variable: (gdb) print my_var, (gdb) watch my_var, (gdb) x (address of var);
(5) Other utilities: (gdb) backtrace, (gdb) finish.

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注