组测试单元

我被困在如何编写测试上。我有以下公共功能。GetAccountNumber()有自己的逻辑。我想返回一个模拟值GetAccountNumber()。在 Java 中,我可以做到when(object.method()).thenReturn("returnValue"). 是否有类似的东西可用于 go 我如何才能做到这一点。我正在浏览一堆 go 文档,但还没有发现任何有用的东西。


func GetConfigName() string {

    var configName string

    accountNumber := GetAccountNumber()

    switch *accountNumber {

    case "123":

        configName = "test1"

    case "456":

        configName = "test2"


    return configName

}


一只甜甜圈
浏览 108回答 1
1回答

拉风的咖菲猫

要为这个函数编写单元测试用例,我们需要先看GetAccountNumber()函数定义。有关在 Go中编写单元测试用例的更多信息,请参阅“在 Go 中轻松进行单元测试”。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go