如何在Golang中以相同的结构方法模拟结构方法?

时间:2017-01-18 12:46:32

标签: unit-testing go mocking

我有嘲弄的麻烦..我有相同的代码:

.container{
    width: 100%;
}
.container > .inner-block{
    display: inline-block;
    position: relative;
    width: calc(25% - 13px);
    height: 0;
    padding-bottom: calc(25% - 13px);
    margin: 5px;
    background: blue;
}

方法B的测试代码:

type OtherInterface interface {
   Do() error
}
type MyInterface interface {
   MethodA() error
   MethodB() error
}
type MyStruct struct {
  OtherStruct OtherInterface
}
func(s *MyStruct) MethodA() error {
  return s.MethodB()
}
func(s *MyStruct) MethodB() error {
  return s.OtherStruct.Do()
}

但我如何测试MethodA?

是的,我也可以模拟OtherStruct并且不使用模拟的MethodB,但是在大结构中我可以有很多字段和其他结构,但是使用一个内部方法..

0 个答案:

没有答案