Golang Unit Testing

Viewed 182

I am stuck on how to write tests. I have following public function. GetAccountNumber() has its own logic. I would like to return a mock value for GetAccountNumber(). In Java, I could do when(object.method()).thenReturn("returnValue"). Is something similar available for go how can I accomplish that. I am going through bunch of go documentation but have not found anything useful yet.

func GetConfigName() string {
    var configName string
    accountNumber := GetAccountNumber()
    switch *accountNumber {
    case "123":
        configName = "test1"
    case "456":
        configName = "test2"

    return configName
}
1 Answers

For writing a unit test case for this function, we need to see the GetAccountNumber() function definition first.

Please see "Unit Testing made easy in Go" for more information on writing unit test cases in Go.

Related