<p>I'm trying to implement a simple <code>assertEquals</code> function. I'm at the point when I don't understand how object equality works. Please have a look at this example (simplified for brevity): <a href="https://play.golang.org/p/bFv6KJcxcr8" rel="nofollow">https://play.golang.org/p/bFv6KJcxcr8</a>
Why does it produce this result? I'm sure this is related to the fact that the type of <code>expected</code> is <code>interface{}</code>, but I'd appreciate if someone could explain this behaviour.</p>
<hr/>**评论:**<br/><br/>_zombiezen_: <pre><p>What you are seeing is the same as this FAQ: <a href="https://golang.org/doc/faq#nil_error" rel="nofollow">https://golang.org/doc/faq#nil_error</a></p>
<p>Slice nil is not the same as interface nil, they are two different types.</p>
<p>You may want to look at something like <a href="https://github.com/google/go-cmp" rel="nofollow">https://github.com/google/go-cmp</a> for your tests instead.</p></pre>shovelpost: <pre><p>The standard library equivalent of an <code>assertEquals</code> function is to use <code>reflect.DeepEqual</code>.</p>
<p>But recently the Tech Lead for Go on Cloud at Google mentioned that using <code>reflect.DeepEqual</code> can lead to <a href="https://medium.com/@zombiezen/life-of-a-go-infrastructure-maintainer-cb1419308eb5" rel="nofollow">fragile tests</a>. So... ¯\_(ツ)_/¯</p></pre>Ch00ki: <pre><p><code>reflect.DeepEqual</code> also returns <code>false</code> in this particular case.</p></pre>shovelpost: <pre><p>Well yeah because <code>[]string(nil)</code> and <code>nil</code> are different types.</p></pre>