单元测试是否应该涵盖压力测试? [英] Should unit tests cover stress testing?

查看:47
本文介绍了单元测试是否应该涵盖压力测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道你们是否有任何好的阅读来考虑将什么归类为单元测试/验收/集成测试.我有以下场景,我们正在讨论是否应该在单元测试中进行:

I am wondering if you guys have any good reading to consider what to classify as unit testing / acceptance / integration testing. I have the following scenario and we're having a bit of a debate at work if it should be in unit tests:

在我们的数据访问层,有一些语句使用sql比如select * from people where id IN('x','y'),这里的IN语句是根据输入动态生成的.最近我们发现我们的 Oracle 数据库在 IN 语句中限制为 1000 个变量.

In our data access layer, some statements use sql such as "select * from people where id IN ('x', 'y'), where the IN statement is dynamically generated according to the input. Recently we found out that our Oracle db have a limit of 1000 variables within the IN statement.

我个人认为这不是单元测试场景.我们在单元测试中测试 sql 是否对数据库有效,以及逻辑是否正确.但是,压力测试应该在更高的层次上进行.

I personally think this is not a unit testing scenario. We test if the sql work against the database in unit tests and if the logic is right. However, stress testing should be done at higher level.

如果我们要在单元测试中用 1000 条记录进行测试,我们每次都需要用大量记录填充数据库,这可能效率低下.

If we are to do testing with 1000s of records in unit tests, we need to fill the database each time with large number of records, which might be inefficient.

有什么建议吗?

推荐答案

关于你的具体例子,你实际上应该考虑为它做 2 个测试:

Regarding your particuliar example, you should in fact consider to do 2 tests for it:

  • 第一个是单元测试,将检查您的函数是否可以接受需求所请求的最大输入数量.如果那里没有指定任何内容,请向分析师要求澄清.像这样动态生成的请求在之后调试起来很麻烦.
  • 第二个是压力测试.但是它不应该在代码的这个特定部分执行,而应该在将使用它的集成部分执行.如果您开始对单元块进行压力测试,您最终会过早地进行优化,因为您将失去全局并开始假设这将如何协同工作,而不是观察它的实际效果.

这篇关于单元测试是否应该涵盖压力测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆