java - Spring Test @ActiveProfiles 替代方案?
问题描述
我想为带有外部变量的测试设置活动配置文件 - 例如,VM 选项。我有任何变化吗?
变体 1:@ActiveProfiles
用变量设置,比如@ActiveProfile("${testProfile:test}")
- 不工作或者我不知道如何。
变体 2:具有任何上下文设置,例如WebContextInitializer
(不适用于测试)。
有什么想法吗?
解决方案
您可能可以使用 ActiveProfilesResolver
请参见下面的示例:
public class MyActiveProfilesResolver implements ActiveProfilesResolver{
@Override
public String[] resolve(Class<?> testClass) {
String os = System.getProperty("os.name");
String profile = (os.toLowerCase().startsWith("windows")) ? "windows" : "other";
return new String[]{profile};
}
}
@ActiveProfiles(resolver = MyActiveProfilesResolver.class)
public class MyServiceTests {
}
推荐阅读
- android - Android:recyclerview中的itemdecoration为文本,并且仅在满足特定条件时
- python - 熊猫将年,季度转换为整数
- arrays - Shell脚本中的数组连接
- java - 使用计费客户端从 google play 检索特定用户的 Inapp 购买
- java - 如何将此 Observer 转换为 lambda
- javascript - Laravel:如何在删除按钮上添加确认?
- php - JSON 中的动态变量以 PHP 显示
- c# - 如何在Kafka中使用不同编程语言的多个消费者用于相同的组ID
- php - 如何在 Symfony 4 中通过文件上传提交和验证 multipart/form-data 表单?
- python - Python:计算两个地理编码点之间的角度和距离,同时改变给定点的高度