语言:科特林
目标是测试一个内部调用的方法System.getenv
,我想让这个方法产生一个预定义的结果
试过:
mockkStatic(System::class)
every {
System.getenv(any())
} answers {
when {
firstArg() as String == "clientId" -> "aaa"
firstArg() as String == "clientSecret" -> "bbb"
else -> throw IllegalArgumentException("something went wrong")
}
}
mockkStatic(System::class)
这似乎让 JVM 有点昏昏欲睡:
Exception in thread "main" java.lang.StackOverflowError
Exception: java.lang.StackOverflowError thrown from the UncaughtExceptionHandler in thread "main"
如何测试这样的方法?(可以想象,很多代码使用环境变量)