Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

replace homegrown testing library with something off-the-shelf #358

Closed
rade opened this issue Jan 21, 2015 · 15 comments
Closed

replace homegrown testing library with something off-the-shelf #358

rade opened this issue Jan 21, 2015 · 15 comments
Labels
Milestone

Comments

@rade
Copy link
Member

rade commented Jan 21, 2015

Our testing util library is growing. It's still quite small, but at some point we should probably bite the bullet and pull in something like gocheck or testify.

@rade rade added the chore label Jan 21, 2015
@paulbellamy
Copy link
Contributor

Advantage of testify is that it is a drop-in replacement for our custom testing package.

Have asked @peterbourgon if he has any opinion...

@paulbellamy
Copy link
Contributor

Per f2f discussion with @rade, need to see if gocheck provides better failure stacktraces. testify just gives line-number of assertion, which makes refactoring assertions harder.

@peterbourgon
Copy link
Contributor

I fully endorse the Go philosophy of testing as summarized in the FAQ, quote,

[T]esting frameworks tend to develop into mini-languages of their own, with conditionals and controls and printing mechanisms, but Go already has all those capabilities; why recreate them? We'd rather write tests in Go; it's one fewer language to learn and the approach keeps the tests straightforward and easy to understand.

I suppose testify is preferable to gocheck, and either is preferable to goconvey. But (brutal honesty ahead) I don't see much value in any of these functions and would prefer to just inline them in the relevant tests, eliminating the package altogether.

@rade
Copy link
Member Author

rade commented May 15, 2015

prefer to just inline them

Thereby turning every assertion in a three-line if?!?

@peterbourgon
Copy link
Contributor

Thereby turning every assertion in a three-line if?!?

Sure. For example. Neither newlines nor vertical screen space are limited resources :)

@rade
Copy link
Member Author

rade commented May 15, 2015

That is gross, but I guess we'll just have to agree to disagree.

@paulbellamy
Copy link
Contributor

After trying them: unlike testify, gocheck does give stacktraces of failures

@paulbellamy
Copy link
Contributor

But, does come with a lot of other baggage. :(

@peterbourgon
Copy link
Contributor

Curious: you can generate a stacktrace on demand with debug.PrintStack; what does integration with a testing package get you?

@paulbellamy
Copy link
Contributor

It tells us which test failed, in the case where the assertion is not at the top level. e.g.

func TestSomething(t *testing.T) {
  helper(t)
}

func TestSomethingElse(t *testing.T) {
  helper(t)
}

func helper(t *testing.T) {
  t.Fatal("failure!")
}

Edit: and also the line-number within the test which failed.

@paulbellamy
Copy link
Contributor

So, the options so far seem to be:

  1. Use gocheck, and deal with it's baggage.
  2. Just do all checks inline, with no helper functions
  3. Fork testify/assert, and add stacktraces to it

Of those, I prefer 3. By inlining everything, I worry we'll end up re-inventing stuff all over the place, and end up back where we started.

@peterbourgon
Copy link
Contributor

@paulbellamy what about wrapping Fatals with something that invokes stack.Caller?

@paulbellamy
Copy link
Contributor

@peterbourgon Do you mean like this? Or something else in mind? https://github.com/weaveworks/weave/blob/master/testing/util.go#L133

@peterbourgon
Copy link
Contributor

@paulbellamy Ah, I see. Yes. I'd rename that to e.g. FatalWithStack but that's what I was driving at. Single-purpose wrappers like that are, I think, the best available pattern.

@paulbellamy
Copy link
Contributor

@peterbourgon Right. Given that, I'd also be ok with inlining checks, and using the "XxxWithStack" variants in any helpers.

@rade rade modified the milestone: next May 26, 2015
@rade rade modified the milestone: next Jun 3, 2015
@rade rade modified the milestone: 1.1.0 Jul 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants