mardi 6 septembre 2016

How to build mock class in golang?

I'm trying to build mock class for unit test in golang; does anyone know how to do that? For example, in the following code slice, I'd like to print FakeMyClass.Object's return value.

package main

import (
    "fmt"
)

type MyClass struct {
}

func (*MyClass) Object() (int) {
    return 0
}

func (mc *MyClass) PrintInfo() {
    fmt.Printf("%v\n", mc.Object())
}

type FakeMyClass struct {
    MyClass
}

func (*FakeMyClass) Object() (int) {
    return 1
}

func main() {
    mc := &FakeMyClass{}
    mc.PrintInfo()
}

Aucun commentaire:

Enregistrer un commentaire