Great read! You can also use testify's require instead of asserting. For example,
From
ifassert.NotNil(t,err,"unexpected function error"){// here we assert the expected value// but only if the error is nil!assert.Equal(t,got,want,"unexpected function output)
}
To
got,err:=doSomething()require.NoError(t,err)// or require.Nil(t, err) or require.NotNil(t, got)assert.Equal(t,expected,got.SomeValue)
In this case your test will automatically fail before going into the assertion, and not causing a nil pointer exception!
I also like table tests over BDD but that's just my personal preference.
Ilya is a Cloud Native Architect, he is an expert in the world of cloud technologies and distributed systems. He helps SMBs to earn more and spend less with proper cloud decisions.
Great read! You can also use testify's
require
instead of asserting. For example,From
To
In this case your test will automatically fail before going into the assertion, and not causing a nil pointer exception!
I also like table tests over BDD but that's just my personal preference.
Nice point, thanks!