依赖外部服务的集成测试

发布于 2024-12-11 18:59:53 字数 241 浏览 3 评论 0原文

我目前正在为我的系统编写集成/功能测试。部分功能是通过 http(我运行的另一个系统)访问 Web 服务。

我应该如何设置 Web 服务的测试实例以进行良好的功能测试?我想让我的系统使用实时生产数据针对此服务运行。

Web 服务是否应该是一个独立的实例,始终拥有我手动重新加载的实时生产数据(也许每次启动它的实例时都会重置)?

每次测试时都应该设置和拆除 Web 服务吗?

处理此类情况有哪些常见做法?

I am currently writing integration/functional tests for my system. Part of the functionality is to hit a web service via http (another system I run).

How should I set up a test instance of the web service to allow for good functional testing? I want to have my system run against this service with live production data.

Should the web service be an independent instance that always has the live production data that I reload manually (maybe reset every time I start an instance of it)?

Should the web service be setup and teared down with every test?

What are some common practices to deal with situations like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2024-12-18 18:59:53

首先,请确保您了解功能测试集成测试。您可以进行相当不错的功能测试,而无需集成测试(实例化 Web 服务、访问数据库)所需的大量工作。基本上 Mocking 技术甚至可以很好地模拟数据层响应和 Web 服务行为(我相信这样对于大多数测试用例,HTTP 作为传输之类的细节可以被忽略)

对于这样的集成测试,我建议有一个单独的 SIT 环境,其中包括一个单独的 Web 服务和一个数据库作为出色地。

Web 服务是否应该是一个始终拥有实时生产数据的独立实例
我手动重新加载(也许每次启动它的实例时都会重置)?

是的,它应该完全独立,但可以手动生成/准备数据。例如,您可以准备一些数据集来测试一些预定义的测试用例,这可以是在实际测试运行之前部署到 SIT 数据库实例,然后在测试 TearDown 中清理的测试数据集。

每次测试时都应该设置和拆除 Web 服务吗?

是的,测试应该彼此隔离,因此不应以任何方式影响每一个测试。

As first thing please make sure you know difference between Functional Testing and Integration Testing. You can do a pretty good functional tetsing wthout major efforts which are required by integration testing (instantiating web services, accessing a data base). Basically Mocking technique works pretty well even to simulate the Data Layer responses and web service behaviour (I believe such details like HTTP as transport could be ignored for most test cases)

For such integration testing I would suggest having a separate SIT environment which includes a separate Web service and a Data Base as well.

Should the web service be an independent instance that always has the live production data
that I reload manually (maybe reset every time I start an instance of it)?

Yep, it should be completely separate but data could be manually generated/prepared. For instance, you can prepare some set of data which allows testing some predefined test cases, this could be test data sets which are deployed to the SIT DB instance before the actual test run and then cleaned up in test TearDown.

Should the web service be setup and teared down with every test?

Yep, tests should be isolated one from each other so should not affect each one in any way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文