Replies: 1 comment
-
I would say that in my opinion this highlights a problem in the code, not the test. If you need to mock one method of a class to test another method of the class I would suggest that they do not belong in the same class. Does Can type Server struct{}
func (s *Server) nrCells {
s.extractTA()
}
func (s *Server) extractTA {} Consider: type TAExtractor interface{
extractTA()
}
type Server struct{
TAExtractor
}
func (s *Server) nrCells {
s.extractTA()
} Note that this is not inheritance, your implementation of It's not possible to write the test you want with testify. You'd need to use monkey patching, which is not safe. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I've two method that implement Server :
func (s *Server) nrCells
func (s *Server) extractTA
extractTA is being called inside nrCells.
Since I'm testing nrCells, I would like to mock extractTA.
So I tried with the following Mock structure :
This is not working, I can see extractTA logs, so it's not mocked (and causing panic because of that).
But I also tried a direct call to test the mock :
And this is working well.
There's something wrong when I'm calling it through nrCells.
Question : Is it possible to do what I'm trying to do ? Mock a method called from another method from the same MockObject.
If yes : what's wrong here ?
If not : do I have another to reach my goal ?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions