简体   繁体   English

进行顺序集成测试是否可取?

[英]Is it advisable to have sequential integration tests?

I'm new to integration tests, and currently doing it with SpringBootTest.我是集成测试的新手,目前正在使用 SpringBootTest 进行测试。

Roughly what I'm gathering from examples is that each method would be one integration test (corresponds to one REST call).我从示例中大致收集到的是,每种方法都是一个集成测试(对应于一个 REST 调用)。

But what if I want to test a scenario where it's a sequence of steps?但是,如果我想测试一个包含一系列步骤的场景怎么办? Like Create User->Update User->Delete User.比如创建用户->更新用户->删除用户。

Maybe that's not called an integration test?也许那不叫集成测试? And if so, how do I chain these inside SpringBootTest?如果是这样,我如何将这些链接到 SpringBootTest 中?

Well, it is okay to have a testing order at that level of testing, what I mean with level is this:好吧,在那个级别的测试中有一个测试订单是可以的,我的意思是级别是这样的:

Unit Testing -> Component Testing -> Integration Testing -> end to end testing.单元测试-> 组件测试-> 集成测试-> 端到端测试。

As you move to the right, the tests are more complex to set up and execute.当您向右移动时,测试的设置和执行更加复杂。

In my opinion, the tests you describe are Integration Test, so, having order is fine, but, you should try to avoid adding complexity, for instance, using a mock in-memory database like H2, and populate it when you are testing, helps a lot.在我看来,您描述的测试是集成测试,因此,有顺序是可以的,但是,您应该尽量避免增加复杂性,例如,使用像 H2 这样的模拟内存数据库,并在测试时填充它,有很大帮助。

As the database is in memory, you won't need to take care of cleaning or restoring the state of that database, the data just will be gone after the testing finishes.由于数据库在 memory 中,因此您无需清理或恢复该数据库的 state,测试完成后数据就会消失。

Now, you need to take care of the order of the test methods.现在,您需要注意测试方法的顺序。 JUnit5 uses a new annotation @TestMethodOrder and JUnit4 uses @FixMethodOrder that is not pretty customizable, you can find more information here JUnit5 使用了一个新的注解 @TestMethodOrder,而 JUnit4 使用了不太可定制的 @FixMethodOrder,你可以在这里找到更多信息

And finally, I suggest using something more BDD related like Cucumber for that kind of tests最后,我建议使用更多与 BDD 相关的东西,例如 Cucumber 进行此类测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM