vendredi 12 juin 2020

Is it possible to stub/mock a function call without adding an interface?

Working with a codebase that doesn't have any interfaces in front of its Database calls, I want to test application logic that uses these functions. Is there any way to do this? Here is a simple example

func GetNumbers() []int {
    return []int{1, 2, 3, 4}
}

func ProcessNumbers() bool {
    numbers := GetNumbers()
    numbers = Operation1(numbers)
    numbers = Operation2(numbers)
    return Operation3(numbers)
}

If GetNumbers was a database call, is there anyway for me to stub the return type of this function, without adding a interface of on GetNumbers?

Aucun commentaire:

Enregistrer un commentaire