功能测试应该只断言响应吗?
Should functional test just assert responses only?
我对测试有一些困惑的问题。
我们使用 Slim
作为系统框架。据我所知,Unit Test
是测试的最小值。例如,测试 class 或方法是否按预期工作。
测试系统的另外一个功能,比如系统提供了一个API搜索产品信息的功能,这个搜索功能的设计思路如下:
- Clients post 关键字到 API 条目。例如。
/search
- 处理请求并将
SearchService
注入控制器。
- 将关键字设置为
SearhService
。
- 将关键字推入数据库。例如。
search_history
.
- 将搜索结果取回控制器,并响应客户端。
这就是search API
的设计方式。
我们为 Search API
创建了一个名为 SearchTest
的功能测试。我们是这样做的:
- 使用
Slim
提供的 $this->runApp()
方法向 API 条目发送请求。
- 设置多个测试用例来测试不同类型的场景,例如"No keyword provided"、"No search result"。 ..等等
- 断言 return 值或 HTTP 状态符合预期的响应。
一些问题令人困惑:
- 发送请求并断言响应,就这些了吗?我们是不是误解了所谓的"functional testing"?
- 我们不应该关心它是如何工作的,我们只需要发送请求并断言响应,对吧?
- 如果没有,我们是否应该检查依赖项或使用的组件是否按预期工作?例如,我们是否应该连接数据库,检查关键字推送是否成功?
自动化测试(和一般测试)在软件工程中被认为是一种很好的实践。然而,关于测试方法和类型分类的界限存在很多热议。
从这个意义上说,正确实施测试方法的实用方法是向那些您可能认为在您的软件开发环境中受人尊敬的人学习,并确保实践您采纳对您愿意实现的目标很有帮助。 尝试在这一点上保持一致。
仅供参考,lets take this definition.
Functional testing refers to activities that verify a specific action or function of the code. These are usually found in the code requirements documentation, although some development methodologies work from use cases or user stories. Functional tests tend to answer the question of "can the user do this" or "does this particular feature work."
考虑到这种方法,您希望您的测试让您确信用户能够执行您的应用程序提供的某些功能(或特性)。 (此处)如何 提供该功能并不重要,只需站在用户的角度思考 "Am I getting what I'm expecting from this action?",这个问题应该会提示您测试的断言。
Non-functional testing refers to aspects of the software that may not be related to a specific function or user action, such as scalability or other performance, behavior under certain constraints, or security. Testing will determine the breaking point, the point at which extremes of scalability or performance leads to unstable execution. Non-functional requirements tend to be those that reflect the quality of the product, particularly in the context of the suitability perspective of its users.
如果您想测试如何执行某个函数,它可能是一个单元测试,它可以帮助您进行这些断言。
但是,请再次记住,这并不是严格限制你的测试应该从他们的名字中执行什么,而是要知道什么分类最适合你正在执行的断言类型(这有助于你更好地构建结构你的测试,让你清楚地知道你在测试什么)。 尽量保持一致并专注于测试您真正需要自信的东西。
我对测试有一些困惑的问题。
我们使用 Slim
作为系统框架。据我所知,Unit Test
是测试的最小值。例如,测试 class 或方法是否按预期工作。
测试系统的另外一个功能,比如系统提供了一个API搜索产品信息的功能,这个搜索功能的设计思路如下:
- Clients post 关键字到 API 条目。例如。
/search
- 处理请求并将
SearchService
注入控制器。 - 将关键字设置为
SearhService
。 - 将关键字推入数据库。例如。
search_history
. - 将搜索结果取回控制器,并响应客户端。
这就是search API
的设计方式。
我们为 Search API
创建了一个名为 SearchTest
的功能测试。我们是这样做的:
- 使用
Slim
提供的$this->runApp()
方法向 API 条目发送请求。 - 设置多个测试用例来测试不同类型的场景,例如"No keyword provided"、"No search result"。 ..等等
- 断言 return 值或 HTTP 状态符合预期的响应。
一些问题令人困惑:
- 发送请求并断言响应,就这些了吗?我们是不是误解了所谓的"functional testing"?
- 我们不应该关心它是如何工作的,我们只需要发送请求并断言响应,对吧?
- 如果没有,我们是否应该检查依赖项或使用的组件是否按预期工作?例如,我们是否应该连接数据库,检查关键字推送是否成功?
自动化测试(和一般测试)在软件工程中被认为是一种很好的实践。然而,关于测试方法和类型分类的界限存在很多热议。
从这个意义上说,正确实施测试方法的实用方法是向那些您可能认为在您的软件开发环境中受人尊敬的人学习,并确保实践您采纳对您愿意实现的目标很有帮助。 尝试在这一点上保持一致。
仅供参考,lets take this definition.
Functional testing refers to activities that verify a specific action or function of the code. These are usually found in the code requirements documentation, although some development methodologies work from use cases or user stories. Functional tests tend to answer the question of "can the user do this" or "does this particular feature work."
考虑到这种方法,您希望您的测试让您确信用户能够执行您的应用程序提供的某些功能(或特性)。 (此处)如何 提供该功能并不重要,只需站在用户的角度思考 "Am I getting what I'm expecting from this action?",这个问题应该会提示您测试的断言。
Non-functional testing refers to aspects of the software that may not be related to a specific function or user action, such as scalability or other performance, behavior under certain constraints, or security. Testing will determine the breaking point, the point at which extremes of scalability or performance leads to unstable execution. Non-functional requirements tend to be those that reflect the quality of the product, particularly in the context of the suitability perspective of its users.
如果您想测试如何执行某个函数,它可能是一个单元测试,它可以帮助您进行这些断言。
但是,请再次记住,这并不是严格限制你的测试应该从他们的名字中执行什么,而是要知道什么分类最适合你正在执行的断言类型(这有助于你更好地构建结构你的测试,让你清楚地知道你在测试什么)。 尽量保持一致并专注于测试您真正需要自信的东西。