unit-testing - 无法在 Groovy 测试用例中使用 Mock 从 yaml 文件中获取值
问题描述
我正在使用 Groovy 为我的功能编写一个单元测试用例。但是,我无法配置类中可用的值。这些值在我的 yaml 文件中配置。
这是我的代码
class UpdateServiceImplTest extends Specification {
DataSourceRestTemplateConfig dataSourceRestTemplateConfig
def setup() {
dataSourceRestTemplateConfig= Mock(DataSourceRestTemplateConfig )
}
}
此 DataSourceRestTemplateConfig 类正在使用一些属性,在执行测试时这些属性为 null
public class DataSourceRestTemplateConfig {
@Autowired
RestTemplate restTemplate;
@Value("${datasource.auth.username}")
private String userNameNew;
@Value("${datasource.auth.password}")
private String passwordNew;
// Method to call DB here
}
当我评估表达式时,上述值将变为 null。我还缺少其他配置吗?
任何想法都会对我有很大帮助。
解决方案
推荐阅读
- docker - 通过 Docker compose 文件配置本地代理?
- r - 在 R 模拟中估计线性回归和线性混合模型中的偏差
- python - NameError:加载 keras 模型时未定义名称“feature_extractor_url”
- bash - 通过 ssh 运行多个 rsync 命令并且只输入一次 ssh 密码
- r - 当存在平局时如何总结数据集中的前 3 个最高值
- powerbi - 计算列中的微小差异
- node-modules - 如何使用节点模块中的 Web 组件依赖项部署到 GitHub 页面
- redux - @redux-saga/simple-saga-monitor 是做什么的?
- c - 如何将 printf 的多个值存储在变量中?
- openwrt - 建立 ICMPv4 流后,主机无法 ping