Facebookgo/ensure as a library of handy test helpers

@pawan mentioned that dependency for tests might not be so bad. It is still good to use a simpler library that is stable and easy to understand. testify seems popular but it seems too heavy. I was thinking of the following library which appears to be maintained by Facebook:

This library has <500 lines of actual code, but would help a lot in reducing the verbosity of our tests. It can do deep comparison. It can print out errors nicely. There is no need to write

if a != 3 {
  t.Errorf("Expected 3 but got %v", a)
}

which is repetitive and sometimes inconsistent when we update the value 3. Yes, we can write our own comparison function, but this dependency seems like a small and light one, and as this is only a dependency for tests, the merit of developing and maintaining our own test lib may not outweigh the benefit of having a simple, light, well-written test helpers that can immediately make our tests look more concise and easier to read.

Would love to gather some feedback before I do anything @minions. Thanks.

Add: OK, this library does have its own dependencies…

1 Like

Looks good to me.

Might be also worth checking out testify/assert at master · stretchr/testify · GitHub. We would just need the assert package and not others. Also noticed spew is a common dependency. Though this library seems to have the needed methods and assert just has a whole lot that we might not need right now?

1 Like

I would prefer using testify/assert as well, over facebookgo/ensure. The two dependencies seem to add quite a lot of value to test outputs: spew will print deep array diff while difflib will print text diff, which is useful for comparing JSON outputs.

2 Likes

I think we should be fine using this, given that its only for testing and doesn’t affect the performance of our binaries. I’d say go ahead and use it.

2 Likes

I am still trying to embed icu. If I need to give up for a while, I will work on this. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.