我在 Golang 中有一个调用 python 函数的 API 处理程序。我如何模拟来自 python 函数的响应以避免依赖该函数正确运行来测试 Golang 函数?
最佳答案
您可以将您的函数包装到一个新的 moc 函数中:
func CallPythonFunctionMoc() Result {
var res Result
var err error
res, err = CallPythonFunction()
if err != nil {
res = "Moc value"
}
return res
编辑:
如果您实际上不想调用 python 函数,只需返回 moc 值:
func CallPythonFunctionMoc() Result {
res := "Moc value"
return res
关于python - Golang单元测试python函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44915711/