FAQ
Hi guys,

i see that exists several testing frameworks for golang but i read also
that the language is so flexible that those are effectively not necessary
(most of the time). For that reason i want to go much deeper in order to
better understand how to change a method implementation during a test case
o several test cases.

i know that if i have a struct with an attached method i can override it
directly during my tests, like:

package mypack

type Eg struct {

}

func (e Eg)MyMethod() error {
...
}


And in my test i do something like:

package mypack

func (e Eg)MyMethod() {
   return nil
}

func TestMethodOverride(t *testing.T) {
   e Eg

   if e.MyMethod() != nil {
     t.Errorf("...")
   }
}

Now my point is, there is a way to override the method directly during the
test operation in order to try different scenarios?

func TestAllGoesFine(t *testing.T) {
   // ... method override Eg.MyMethod with nil as error
}

func TestWithError(t *testing.T) {
   // ... method override Eg.Method with Error.New("A failure")
}

Any advice?

Bests
Walter




--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 21, '15 at 11:08p
activeJan 21, '15 at 11:08p
posts1
users1
websitegolang.org

1 user in discussion

Walter Dalmut: 1 post

People

Translate

site design / logo © 2022 Grokbase