我应该在 MQ/Service 架构中测试整个业务流程吗?
Should I be testing an entire business flow in a MQ/Service architecture?
我正在尝试将发送电子邮件的代码分离到一个单独的服务中,rabbitMQ 具有服务之间的通信方式。
目前,我有集成测试来测试我们的 HTTP 端点,就像这样:
1. Create fake data in a dockerized mysql container. So that the DB is in the correct state
2. Perform testable action such as: User needs to approve a contract
3. Expect that the `contract.status` is now `approved`
4. Query a local SMTP server (Mailhog) to see if the email is there
5. Expect that email subject/body contains what I'm expecting
现在我打算加入一个消息队列。我还应该像这样编写集成测试吗?我应该如何编写我的测试,以便我仍然可以测试执行此操作时是否发送了电子邮件。
如果整个解决方案由您负责,您绝对应该为整个解决方案编写集成测试。
如Martin Fowler所述:
Integration tests determine if independently developed units of software work correctly when they are connected to each other.
编写测试取决于您的具体实现。我认为您必须创建测试数据并执行操作(步骤 1 到 3),然后检查结果,无论是否存在 MQ。
我正在尝试将发送电子邮件的代码分离到一个单独的服务中,rabbitMQ 具有服务之间的通信方式。
目前,我有集成测试来测试我们的 HTTP 端点,就像这样:
1. Create fake data in a dockerized mysql container. So that the DB is in the correct state
2. Perform testable action such as: User needs to approve a contract
3. Expect that the `contract.status` is now `approved`
4. Query a local SMTP server (Mailhog) to see if the email is there
5. Expect that email subject/body contains what I'm expecting
现在我打算加入一个消息队列。我还应该像这样编写集成测试吗?我应该如何编写我的测试,以便我仍然可以测试执行此操作时是否发送了电子邮件。
如果整个解决方案由您负责,您绝对应该为整个解决方案编写集成测试。
如Martin Fowler所述:
Integration tests determine if independently developed units of software work correctly when they are connected to each other.
编写测试取决于您的具体实现。我认为您必须创建测试数据并执行操作(步骤 1 到 3),然后检查结果,无论是否存在 MQ。