使用 ApplicationContext 运行 JUnit 测试时禁用 Hazelcast 实例

阿尔特贡

我有这样的 JUnit 5 测试,因为测试速度,我需要在运行测试时禁用创建 Hazelcast 实例。有什么方法可以为一项特定测试禁用 Hazelcast?

@SpringBootTest
@RunWith(SpringRunner.class)
class MemoryTradeCommunicatorTest {
// test cases....
}
尼古拉斯

有三种主要方法可以解决您的问题。我假设您只需要禁用 Hazelcast 并且您正在使用 Spring Boot,尽管您没有明确提及它。

  1. 正如 Dmitrii 提到的,您可以模拟提供 Hazelcast 实例的 bean。请注意,您可能需要将配置拆分为多个片段,以便导入测试所需的 bean。
  2. 您可以使用 Spring 配置文件。您需要创建一个test配置文件并在其中创建一个模拟 Hazelcast 实例。实现在很大程度上取决于您如何创建真正的 Hazelcast 实例(Spring Boot 或手动)。
  3. 由于自动配置类,Spring Boot 创建 Hazelcast 实例。您可以通过排除特定类来防止这种行为在你的情况下,你会启动你的测试spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Mybatis Crud的Spring MVC:使用Junit测试时,错误无法加载ApplicationContext

使用SBT运行JUnit测试

使用IntelliJ运行JUnit测试

使用junit进行多实例测试

尝试使用Spring运行jUnit测试时出现NoSuchFieldError

在SpringBoot项目上使用DBUNIT运行Junit测试时出错

使用Ant运行JUnit测试时出现ClassNotFoundException

无法使用PowerMockRunner运行JUnit测试

在Eclipse下使用Maven运行JUnit测试

使用Maven surefire与mpirun运行Junit测试

如何使用Gradle运行分类Junit测试?

如何使用Gradle运行JUnit测试?

使用Ant仅运行特定的JUnit测试

使用JUNIT测试运行AsyncHttpClient

是否可以使用Spring ApplicationContext中的bean参数化JUnit Jupiter测试?

IntelliJ 使用 NoClassDefFoundError 随机无法为 Spring JUnit 测试加载 ApplicationContext

如何使用Junit配置SpringBoot的按测试方法实例化?

JUnit-使用参数中的对象测试类实例化

在Grails中运行集成测试时无法加载ApplicationContext

运行Spring Boot集成测试时无法加载ApplicationContext

hazelcast 实例正在运行但无法连接到 mancenter

在Intellij 2020.1中运行JUnit测试时如何禁用Security Manager?

运行春季启动测试时得到hazelcast.core.DuplicateInstanceNameException

JUnit多次运行测试

使用JUnit测试5斯波克测试,将不运行

要在hazelcast中存储在IMap中以进行缓存的数据存储在hazelcast服务器中或运行hazelcast实例的位置?

运行测试时,Ant + JUnit = ClassNotFoundExceptions?

运行junit测试时出现ZipException

运行JUnit测试时“未找到类”