简体   繁体   English

是否可以并行运行集成测试(Spring boot)?

[英]Is it possible to run integration tests in parallel (Spring boot)?

Already has a test environment configured for a specific application (several dozen test classes).已经为特定应用程序配置了一个测试环境(几十个测试类)。

TestContainers are also used here.此处也使用了TestContainers

I see such an algorithm :我看到这样的算法

  1. The Application context is raised once, for the entire time of working with tests.应用程序上下文在整个测试过程中被引发一次。
  2. Also raises one container with Postgresql .还使用Postgresql提升一个容器。
  3. Since it is impossible to follow the order of integration tests , so each test will clean up after itself the data that was written to the database.由于无法遵循集成测试的顺序,因此每个测试都会在自己之后清理写入数据库的数据。
  4. Find out from the JVM how many processor cores are allocated to it and create a capacity for the thread pool based on this number.JVM中找出分配给它的处理器内核数量,并根据该数量为线程池创建容量。
  5. Create a thread pool in the class with Application context ( Executors ....) and issue tasks for running test classes for the threads.在 class 中创建一个带有应用程序上下文Executors ....)的线程池,并为线程运行测试类发出任务。
  • Is it possible to control the launch of test classes, that is, how to do it from the code?是否可以控制测试类的启动,即从代码上怎么做?
  1. To run multiple threads simultaneously (according to the number of cores in the current system) we can use CyclicBarrier .要同时运行多个线程(根据当前系统中的内核数量),我们可以使用CyclicBarrier
  2. Or you can use a different approach:或者您可以使用不同的方法:

Again, you need to know how to run all the test methods of this class from an object of the class, with test methods.同样,您需要知道如何从 class 的 object 中运行此 class 的所有测试方法,以及测试方法。

So, we create objects of test classes, and using the Stream API , then call the parallel() method (but here I do not control the number of simultaneously running threads).因此,我们创建测试类的对象,并使用Stream API ,然后调用parallel()方法(但这里我不控制同时运行的线程数)。

What are the options for solving this problem?解决这个问题有哪些选择?

Who has any ideas?谁有什么想法?

I found the answer to my question here我在这里找到了我的问题的答案

2.19. 2.19。 Parallel Execution 并行执行

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

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