您可以让Spring Boot JUnit测试使用同一台服务器吗? [英] Can you get Spring Boot JUnit tests to use the same server?

查看:87
本文介绍了您可以让Spring Boot JUnit测试使用同一台服务器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了一些Spring Boot JUnit测试,这些测试需要较长的服务器启动时间(我正在JPA中加载一个复杂的域).我已经将它们放入一个测试套件中,但是每个测试都会启动一个新的服务器启动.

I have some Spring Boot JUnit tests that require a somewhat lengthy server start up (I'm loading a complex domain in JPA). I've put them into a test suite, but each test kicks off a new server start up.

是否可以将服务器设置为仅启动一次并将每个测试加载到服务器上并像运行服务器本身一样启动服务器来运行它们?

Is it possible to set them up in such a way that the server is only started once and each test is loaded onto it and run as if the server were started by the test itself?

推荐答案

好的,因此这里的解决方案实际上内置于Spring测试中.也就是说,它缓存用于测试的ApplicationContext,如

Okay, so the solution here is actually built in to Spring testing. That is, it caches ApplicationContexts for tests, as described here, as long as the various things like properties are the same.

具有讽刺意味的是,我试图通过使用测试属性来限制加载的内容来加快测试的速度.

Ironically, I screwed this up by trying to speed up the tests by using test properties to limit what was loaded.

这篇关于您可以让Spring Boot JUnit测试使用同一台服务器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆