编写以下测试的正确方法是什么?
为了避免写在包本身里面
var _ Common = (*Stuff)(nil),
var _ Common2 = (*Stuff)(nil)
var _ Common3 = (*Stuff)(nil)
...
``
包东西
东西/common.go
package stuff
type Common interface {
String() string
}
东西/common2.go
package stuff
type Common2 interface {
String2() string
}
东西/stuff_suite_test.go
package stuff
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func Test(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Stuff")
}
东西/stuff_test.go
package stuff
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
}
var _ = Describe("Stuff", func() {
It("implements Common", func() {
var s interface{} = &Stuff{}
_, ok := s.(Common)
Expect(ok).To(Equal(true))
})
})
It("implements Common 2", func() {
var _ Common2 = (*Stuff)(nil) // ok
})
东西/东西.go
package stuff
type Stuff struct {}
func (s *Stuff) String() string {
return ""
}
包库
/lib/lib.go
import "stuff"
func GetCommon() *stuff.Stuff {
return &stuff.Stuff{}
}
/lib/lib_suite_test.go
package lib
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func Test(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Lib")
}
/lib/lib_test.go
package lib
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Lib", func() {
It("can be created", func() {
l := GetCommon()
Expect(l).NotTo(BeNil())
})
}