go - Mock struct golang for testing -
i have following code:
type struct {    somestring string    somenumber int }  func (a *a) somefunction(asd string) error {    //do thinks    return err }  func createastruct() (a, error) {    return a{},nil }  func functiontotest (asd string) error {    //do thinks    a, _ := createastruct()    return a.somefunction(asd) } i want build unit test method "functiontotest", don't want call method "somefunction" of struct. reason need "subclass" of implements "dummy" "somefunction".  can this?
i trying refactor method creating following struct:
type acreator struct {   createa  func() (a, error) } var acreator = acreator{createa: createastruct}  type struct {    somestring string    somenumber int }  func (a *a) somefunction(asd string) error {    //do thinks    return err }  func createastruct() (a, error) {    return a{},nil }  func functiontotest (asd string) error {    //do thinks    a, _ := acreator.createa()    return a.somefunction(asd) } with step in test file y can create "setup()" replace method createastruct() , return implementation of implements "dummy" method somefunction(asd string).
is posible? wrong in think? can this?
 
 
Comments
Post a Comment