简体   繁体   English

测试中的TypeSafe配置(无法将替换解析为值)

[英]TypeSafe config in tests (Could not resolve substitution to a value)

All, 所有,

I am using the HOCON based typesafe config in a project. 我在项目中使用基于HOCON的typesafe配置。

This is a Scala project, and we are striving for 100% test coverage. 这是一个Scala项目,我们正在努力实现100%的测试覆盖率。

I have two test configs: test1.conf and test2.conf ... here is the code for loading 我有两个测试配置: test1.conftest2.conf ...这是加载代码

object TypeSafeTestConfigProvider {
  System.setProperty("foo","value")
  System.setProperty("bar","value")
  val config1 = ConfigFactory.load("test1.conf")
  val config2 = ConfigFactory.load("test2.conf")
}

neither foo nor bar can be resolved for some reason if I run a single test ... yet they resolve without an issue if I run all my tests together ... which is very inconvenient. 如果我运行一个测试, foobar都不能由于某种原因而解决...但是如果我一起运行所有测试,它们都可以解决而没有问题...这非常不方便。

It appears the ConfigFactory class takes a static snapshot of System.properties and future changes to System properties are not reflected in the resolution process. 看样子ConfigFactory类需要的静态快照System.properties和系统性能的未来变化不会反映在决议过程。

How would you recommend I setup my tests? 您如何建议我设置测试?

com.typesafe.config.ConfigFactory.invalidateCaches(); did the job for me. 为我做了工作。 Playing with System Properties in unit tests is a Pain. 在单元测试中使用“系统属性”是一种痛苦。

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

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