vendredi 15 avril 2016

Extending existing type testing.T for adding extra checks

I realize I could pass the testing.T type to the functions that need to deal with the testing interfaces. But how about extending the struct and using it? I know I can type extend but this doesn't work unfortunately:

package test

import "testing"

type testingT testing.T

func (t *testingT) assert(val int) {
    if val == 0 {
        t.Errorf("%d is zero", val)
    }
}

func TestSomething(t *testingT) {
    t.assert(0)
}

Aucun commentaire:

Enregistrer un commentaire