摘要
初级程序员开发的程序一般是小规模程序。对于小规模程序,软件工程实践采用的重型测试方法是不适用的,因为测试代码量远大于程序代码量。论文描述三种面向小规模程序的轻型测试方法。第一种方法是"使用freopen函数的方法",做法是在程序中调用freopen函数把输入输出重定向至文件,并用文件比较命令来比对输出结果和期望结果是否一致。好处是免除手工输入和人工比对,消除繁琐和减少犯错的机会。第二种方法是"使用重定向和批处理程序的方法",实质与第一种做法类似,但能够批处理地使用多组测试数据对程序进行测试。第三种方法是"轻型单元测试方法",做法是把程序分解成多个函数,对函数进行测试。好处是便于定位错误。上述三种轻型程序测试方法的优点是易学易用,适用于在OJ网站刷题和计算机软件能力认证考试等场合。
Programs developed by elementary programmers are usually small-scale.It is not suitable to apply heavy test methods used by software engineering practices on small-scale programs,for the lines of test codes is much more than the lines of functional codes.This paper describes three light test methods on small-scale programs.The first one is called the Use of Freopen Function method,which redirects standard input and output of a program to files by calling the freopen function of the C language,and compares the output data file with the expected data file by using the File Compare Command.This method avoids manual input and artificial comparison,eliminates tedious and reduces the chances of making mistakes.The second one is called the Use of Redirection and Batch method,which is substantially same as the first method.At one time,the second method can repeatedly test a program by using of several sets of test data,but the first one can't.The third method is called the Light Unit Test method,which decomposes the whole program into several functions and tests the functions respectively.While using this method,it is convenient to locate where the mistakes are among the codes.The three methods are easy to learn and easy to use.It is appropriate to use them when solving problems from Online-Judge websites and from tests of the Certified Software Professional.
出处
《软件》
2015年第10期90-93,共4页
Software
关键词
软件工程
轻型测试方法
小规模程序
重定向
单元测试
Software engineering
Light test Methods
Small-scale program
Redirection
Unit test