anderseknert,
@anderseknert@hachyderm.io avatar

Question: what's the max time that you'd find acceptable for your unit tests to run?

And I'm well aware that there's a bunch of considerations, no right answer, and so on. Just curious to learn what people think.

ringods,
@ringods@hachyderm.io avatar

@anderseknert less than the time it takes me to get a cup of coffee.

HarkMahlberg,
HarkMahlberg avatar

@anderseknert I would look at the runtime of my unit tests as a function of the size of the codebase. Unit tests running for 1 hour for a single-page app that plays Solitaire and nothing else? Probably would look into improving that runtime. Unit tests running for 1 hour for a fully featured online banking platform? Maybe that's to be expected, carry on.

bluGill,
bluGill avatar

@anderseknert 20 seconds, but that is only for unit tests that could possibly fail based on the code that changed. If I do a full rebuild (which CI does every time) tests should take 5-10 minutes (we are a multi-repo org - which has pros and cons but overall I think is better than single repo for us) - anything else means the repo is too small and so overhead of working with another repo is too high, anything more and the repo is too large and should be split because of the overhead of a large repo is too high.

I don't really believe in a distinction between unit and integration tests. However I do see value in long test which I would not run as part of my normal TDD cycle, instead I would let my CI system deal with them. I have a dozen different builds on my CI system (embedded system where we target several different CPUs, plus we run things like clang-tidy on CI that developers don't normally run locally)

elejia,
@elejia@hachyderm.io avatar

@anderseknert This is something where I do think there is a right answer actually... around 2 mins. Anything longer should either be refactored into smaller, more granular tests or the whole test should be moved to a less frequently run stage downstream.

There are always exceptions to the rule but this is a good guideline in my experience

anderseknert,
@anderseknert@hachyderm.io avatar

@elejia Yeah, it's happened to me on a few occasions that a slow running test suite led to some great refactoring, and even that parts of a project spun off into separate libraries, which of course could be tested independently. Creating libraries from commonly used code is often a good way to force one to consider public interfaces vs. internal, and a bunch of other nice side effects (like the aforementioned test suite run time)

elejia,
@elejia@hachyderm.io avatar

@anderseknert Yeah - I mean, one has to be pragmatic about the right solution at the time, and sometimes just letting it run is that solution.

That being said, I'll grab my soapbox and argue that disabling the test, which I see far too often, is almost never the right solution.

ferrata,
@ferrata@hachyderm.io avatar

@anderseknert i think the rule for me is the faster the better. for unit tests i would personally want seconds, not minutes.

anderseknert,
@anderseknert@hachyderm.io avatar

@ferrata Agreed, but it's hard to achieve in complex projects.

ferrata,
@ferrata@hachyderm.io avatar

@anderseknert of course! i would also add, that acceptable should probably be considered together with feasible. if achieving faster tests is feasible, then having slow tests is unacceptable 😅

khalidabuhakmeh,
@khalidabuhakmeh@mastodon.social avatar

@anderseknert @rogerlipscombe As long as they need to be valuable and accurate.

anderseknert,
@anderseknert@hachyderm.io avatar

@khalidabuhakmeh @rogerlipscombe Of course, but if you can have that in 5 minutes rather than 10, I'm sure you'd be interested? :)

khalidabuhakmeh,
@khalidabuhakmeh@mastodon.social avatar

@anderseknert @rogerlipscombe Of course, give me faster speeds please 😅

That said, I've been guilty of "optimizing" important parts of a test away for speed and not realizing it until weeks later. 🤣

anderseknert,
@anderseknert@hachyderm.io avatar

@khalidabuhakmeh @rogerlipscombe Yes, been there too 😬😅

rogerlipscombe,
@rogerlipscombe@hachyderm.io avatar

@anderseknert in my Erlang projects, I'm happy with somewhere under 5 minutes for unit tests. For integration or end-to-end tests, maybe 20-25 minutes.

dln,
@dln@mastodon.social avatar

@anderseknert for inner-loop while programming, probably <30s at the most. I do enjoy liberal use of tagging tests that are slow. testing.Short in golang, bazel's native "test timeout" tagging, or whatever works with the toolchain at hand.

And on pre-commit, or once in a while on-demand, run the entire test suite.

Also, all manner of caching to only run tests affected by changed code helps tremendously. gotestsum makes me happy for golang projects

But yeah, seconds not minutes!

anderseknert,
@anderseknert@hachyderm.io avatar

@dln Huh, I had somehow missed testing.Short before! But it seems I get that with tags for slow tests anyway, or is there more to it?

While coding I normally test the package I'm working on, then run the full unit tests before pushing.

dln,
@dln@mastodon.social avatar

@anderseknert asfaik there's no more to it that the ability to (manually) tag up tests as "short or not" :D. I'm guessing there's more to the story internally at goog.

Bazel has a slightly richer "tags" mechanism, which one can use for tests as well. https://mickey.dev/posts/go-build-tags-testing/

The only similar way I know of tagging tests in Go is to use build tags, which works alright for separating integration tests and messier stuff like that.

https://mickey.dev/posts/go-build-tags-testing/

Maybe there's a better way?

anderseknert,
@anderseknert@hachyderm.io avatar

@dln Yeah, we use build tags for that purpose in OPA. Slow tests, Wasm, and so on. It works quite well IMHO.

bazscott,
@bazscott@mastodon.social avatar

@anderseknert Locally two minutes, on CI ten minutes.

Yes I realise those things are in conflict and will take some shenanigans to work like that 😀 But mostly locally I'm just running one file of tests.

anderseknert,
@anderseknert@hachyderm.io avatar

@bazscott Same!

taijidude,
@taijidude@hachyderm.io avatar

@anderseknert I mostly work with Java. The faster the better. But i would be okay with up to 5 minutes.

benjamineskola,
@benjamineskola@hachyderm.io avatar

@anderseknert I don’t think I’ve ever worked somewhere where tests took less than 10–20 minutes or similar, so I have no idea what would be reasonable to expect that’s lower than that.

Faster would obviously be preferable but it’s impossible to say this is unacceptable.

If it was hours, then that would definitely be too much.

anderseknert,
@anderseknert@hachyderm.io avatar

@benjamineskola Did you never start on a greenfield project? It's interesting doing that, and see how all the things you'd normally curse in legacy projects eventually grow in your own creation. Long test times certainly included!

benjamineskola,
@benjamineskola@hachyderm.io avatar

@anderseknert Not at work, no — personal projects yes, but they’re all much smaller of course. And I can definitely imagine it would mean either making all the same mistakes, or, by avoiding them, making a whole new different set of mistakes.

anderseknert,
@anderseknert@hachyderm.io avatar

@benjamineskola Haha, yes, that. But they're at least initially "interesting" mistakes. Not so much once the novelty's worn off. It's a humbling experience though.

danlyke,
@danlyke@researchbuzz.masto.host avatar

@anderseknert I've worked on systems that took hours to build completely (roughly 15 minute change one file compile link cycle), and we had test suites that ran for tens of hours. And were super helpful (eg: replay keystrokes while shuffling memory with every allocator call).

I love fast turnaround, but it's fine to have tests that take hours or days...

anderseknert,
@anderseknert@hachyderm.io avatar

@danlyke Wow! And yeah, I'm 100% with you. Gotta be crying if one of the tests failed after 10 hours though!

windrunner,
@windrunner@toot.community avatar

@anderseknert 5 minutes.

anderseknert,
@anderseknert@hachyderm.io avatar

@windrunner That's a precise and definite answer — I like that! Which programming language would that normally apply to?

rogerlipscombe,
@rogerlipscombe@hachyderm.io avatar

@anderseknert it would be interesting to see variation by language/platform. I know that the C++ folks I used to work with were more tolerant of long-ish build/test cycles.

anderseknert,
@anderseknert@hachyderm.io avatar

@rogerlipscombe Totally! Once a project grows beyond a certain size, I normally just run the tests related to my changes locally, and the full test suite only in CI. Mostly hacking on Golang, and the tests are generally fast, but there are lots of them and I'm impatient 😅

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • InstantRegret
  • GTA5RPClips
  • Youngstown
  • everett
  • slotface
  • rosin
  • osvaldo12
  • mdbf
  • kavyap
  • cubers
  • megavids
  • modclub
  • normalnudes
  • tester
  • khanakhh
  • Durango
  • ethstaker
  • tacticalgear
  • Leos
  • provamag3
  • anitta
  • cisconetworking
  • JUstTest
  • lostlight
  • All magazines