51Testing软件测试论坛

标题: Unit testing for speed?(在单元测试中考虑性能测试) [打印本页]

作者: skinapi    时间: 2005-7-27 15:46
标题: Unit testing for speed?(在单元测试中考虑性能测试)
Unit testing for speed?
I was just thinking about performance testing, and wondered if writing a unit test would be sensible. If a functional requirement is, for example, "Import all of the data in the crime scene XML file into the database within 0.5 seconds", a test could be written to:

Get the time into startTime
Call the ImportCrimeSceneData method
Get the time into endTime
Assert endTime < startTime + 0.5 seconds
If this fails, then the ImportCrimeSceneData method can be tuned until it passes. Once it has passed, then any future changes to the method are checked automatically to ensure that the limit isn't exceeded.

Although the idea seems like it would work, it feels like a wrong thing to do. Has anyone else done this successfully, or can anyone give me an actual reason why this is wrong (other than "it just feels like it")?
作者: skinapi    时间: 2005-7-27 15:57
一些参与讨论的人还提供了以下链接供学习参考:
http://javapronews.com/javaprone ... gwithJUnitPerf.html

我的看法:
1、什么时候开始性能测试有时候是一件很难确定但又必须去面对的事情,不是只有系统测试阶段需要考虑性能测试,单元测试、集成测试阶段都有可能和性能测试拉上关系。
2、文中提到如果在单元测试阶段就考虑性能测试,这样在代码发生改变或者对代码进行了优化时就能看出这些改变是否会影响到性能,能尽早的发现代码变更对性能的影响。
3、一个系统的性能如果拆分来看,可以看成若干单元性能的一个有机结合,单元的性能势必也会对整个系统的性能产生影响,所以尽早考虑性能测试是很必要的,当然这需要很好的分析和设计了。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2