TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Slow Tests Are the Symptom, Not the Cause

36 pointsby orendover 11 years ago

11 comments

lmmover 11 years ago
In my experience when you do this you end up with anaemic tests that are basically useless. As the page comes close to admitting, all you do is write the same code twice. The result is a lot of wasted effort on unit tests that never fail.<p>In an app designed like this the integration tests are the useful ones, because they&#x27;re more contentful and test assumptions that are more likely to be wrong. The article flatly asserts that code written in this extremely decoupled style will require fewer integration tests, but I see no evidence for this. And you still need to figure out how to make them run fast.
评论 #6470305 未加载
评论 #6470478 未加载
评论 #6472223 未加载
programminggeekover 11 years ago
Pluggable systems (loose coupling) are the easiest way to create a system that is cheap and easy to maintain. I&#x27;ve found that a lot of Rails developers in particular don&#x27;t see the benefits of this and they really, really like tightly coupled systems because of the convenience of it all.<p>Benefits like fast, easy testing, easier maintenance, swappable external things like databases, queues, external api&#x27;s are apparently not enough of a benefit to change away from rails.<p>I wrote a pattern (<a href="http://obvious.retromocha.com" rel="nofollow">http:&#x2F;&#x2F;obvious.retromocha.com</a>) that makes pluggable systems easy based off of ideas from Uncle Bob, Alistair Cockburn, and Kent Beck which I think makes writing pluggable systems a lot easier, but as with all similar structures like Hexagonal Architecture and the like, Rails devs seem to not see the value in it until their app is a complete mess, at which point they would rather add more rails code than fix the underlying problems.<p>For a lot of developers, now that rails is popular, rails IS the architecture and things that go off the rails are either a waste of energy or too difficult.<p>Rails is what Kent Beck calls a connected architecture and as his incredibly scientific graph describes, the cost of change spikes dramatically over time compared to a modular architecture: <a href="http://www.threeriversinstitute.org/blog/wp-content/uploads/2009/08/connectedAndModularDesign.jpg" rel="nofollow">http:&#x2F;&#x2F;www.threeriversinstitute.org&#x2F;blog&#x2F;wp-content&#x2F;uploads&#x2F;...</a><p>Until developers adopt modular or at least more service oriented designs, nobody should be surprised by slow tests, features taking too long to ship, the cost to ship code to rise dramatically over time. It&#x27;s mostly our own fault.
评论 #6470693 未加载
评论 #6470572 未加载
评论 #6470708 未加载
评论 #6470921 未加载
bradheover 11 years ago
Was mostly with the author right up until he shows an example of the worst possible unit test. Testing the implementation and not the intent.<p>This feels like how Spring must have been born. Trying to think of an alternative, and I think I would be happy with the fat controller example originally given. It&#x27;s simple enough and straight forward.<p>Perhaps it&#x27;s just bad examples all the way around...
评论 #6470338 未加载
评论 #6470070 未加载
评论 #6470120 未加载
评论 #6471002 未加载
schmrzover 11 years ago
I don&#x27;t know (and don&#x27;t care) if this makes your unit tests faster, you shouldn&#x27;t write code like that. He took something that should be simple and made it really complicated. The execution time of your tests shouldn&#x27;t dictate how you will design and write your application. Especially if it makes things harder to maintain and understand.<p>Edit: I love tests and they should be fast so that you can run them every time before pushing your changes but as I said they shouldn&#x27;t dictate how you design and write your application.
评论 #6470542 未加载
评论 #6472260 未加载
VeejayRampayover 11 years ago
Isn&#x27;t part of the problem the fact that Ruby is ridiculously slow? I&#x27;m not even trolling, I am a Ruby programmer, I&#x27;ve used the language for about 5 years now and seeing friends of mine run their 200+ files test suite in under half a second (C programmers), I can&#x27;t help but think about how nice that must be to be able to run your tests when you want to without thinking of the consequences (and yes I understand comparing C and Ruby is ludicrous, just pointing to the fact that Ruby is still extremely slow and would very much benefit from a good speed bump eventually).<p>Cause slow tests as a symptom pretty much means that if you&#x27;re not an excellent programmer then tough sh*t, testing will be slow and painful, which ultimately drives people away from those good practices.<p>Also, I find ironic that Rails (as a framework that is supposed to empower people and make them efficient) is, according to many comments in this thread and &quot;tech pundits&quot; conducive to the kind of tight coupling and dependency that will lead to bad design choices and slow tests.
评论 #6472216 未加载
huntedsnarkover 11 years ago
The slowest part of most tests suites are the integration and acceptance tests. Regardless of how decoupled my actual domain logic is, these will usually be the bottleneck, so I can&#x27;t really agree with slow tests always being a symptom of some underlying architecture problem.
评论 #6472298 未加载
garethadamsover 11 years ago
Not a fan of the way the link jumps to the Disqus comments rather than just being at the top of the page
评论 #6470029 未加载
yxhuvudover 11 years ago
Personally I would have<p>1: Added a users resource beneath the mailing list, ie<p><pre><code> resources :users resources :mailing_lists do resources :users end </code></pre> add_foo is almost always a sign that a new nested controller should be made, and there is almost always a need for a delete as well - in this case users should be able to remove themselves from a mailing list.<p>2: Put the add method on the mailing list and not on the user, because that is where I&#x27;d expect the least logic to be.<p>because:<p>3: I&#x27;d put the actual mailing list mailer logic in a separate class for the configuration of it.
matlockover 11 years ago
We&#x27;ve published two blogposts how we sped up our test and boot times considerably. Maybe helpful to some:<p><a href="http://blog.codeship.io/2013/08/21/faster-test-suite-boot-times-with-ruby-on-rails.html" rel="nofollow">http:&#x2F;&#x2F;blog.codeship.io&#x2F;2013&#x2F;08&#x2F;21&#x2F;faster-test-suite-boot-ti...</a><p><a href="http://blog.codeship.io/2012/11/15/speeding-up-our-test-suite.html" rel="nofollow">http:&#x2F;&#x2F;blog.codeship.io&#x2F;2012&#x2F;11&#x2F;15&#x2F;speeding-up-our-test-suit...</a>
评论 #6471549 未加载
gingerlimeover 11 years ago
after reading sandi metz POODR[1], I tend to prefer the approach on the post too. However, I also must say that the time it takes to execute unit tests, even with factories, db access etc is still an order of magnitude <i>faster</i> than running things like feature tests with capybara. This is by far the biggest drain on test time (and resources), and these are also the tests most difficult to write and maintain. Way too often, when we decide to change some functionality, there&#x27;s a whole battle with tweaking capybara tests to work again.<p>Perhaps I&#x27;m showing my lack of knowledge or experience with capybara, or integration testing, but that&#x27;s one aspect I wish there were some better tools &#x2F; approaches. Having to dig through css&#x2F;xpath elements to click on or perform interaction is still a major PITA. If anybody has some suggestions to share, I&#x27;d love to learn more!<p>[1]<a href="http://www.poodr.com/" rel="nofollow">http:&#x2F;&#x2F;www.poodr.com&#x2F;</a>
评论 #6472289 未加载
mguterlover 11 years ago
It&#x27;s worth stating that this is the MailingListsController and there is no mention of a MailingList. It seems to me like some functionality in the &quot;before&quot; example could live in the MailingList class.