spring - 创建依赖于另一个测试用例的测试

标签 spring unit-testing testing tdd integration-testing

我目前正在开发一个将文件上传到 Web 服务的应用程序(使用 spring resttemplate)。此上传函数返回一个 id,稍后可用于下载上传的文件。

我希望测试涵盖此场景(我不是在谈论单元测试 - 可能是集成测试或功能测试,以适当者为准)。

我想做的是下载测试用例将取决于上传测试的结果(因为 id 将来自上传功能)- 这将针对实际的网络服务进行测试,以确认上传是否成功下载功能正常。

我不确定我想做的这种方法是否正确,所以如果有人可以建议一种好的方法来实现它,我们将不胜感激。

提前致谢!

最佳答案

由于此上传/下载功能已包含在单元级别

I want this scenario covered by a test (i'm not talking about unit test - maybe integration or functional test, whichever is appropriate).

我知道Test chaining被认为是有害的

the download test case will depends on the result of the upload test (since the id will comes from the upload function)

并且可能导致测试之间有很多重叠,因此对一个测试的更改可能会向外级联并导致到处都失败。此外,测试应该具有原子性(隔离)。但是,如果您的案例适合您,我的建议是使用它。

你能看到的,是一个合适的Test Fixture战略。其他Fixture Setup模式可以帮助你。

关于spring - 创建依赖于另一个测试用例的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33360098/

相关文章:

java - Spring如何用环境变量替换${}?

perl - 为什么我需要知道使用 Test::More 将运行多少个测试?

.net - .NET项目中单元测试和验收测试的实现

php - 如何在 PHP 中为接口(interface)编写测试

java - 具有重叠位置的多个属性占位符不起作用?

java - 我们如何使用Spring获取应用程序根目录的绝对路径?

reactjs - 单元测试 Apollo,在 mutation mock 上出错

testing - 使用 Spock 在不同的测试环境中运行测试

java - Spring集成中的并发处理

unit-testing - 'too simple to break' 有多简单? - 解释