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.

Test driven development at Transloadit

133 pointsby felixgeover 14 years ago

14 comments

jsdaltonover 14 years ago
Do you find it hard to change directions with a feature or component, because your tests have sort of "locked you in" to the structure you were working on?<p>How religiously do you follow TDD? Do you literally not write a single line of code unless it's in furtherance of passing a failing unit test, or do you just worry about the system test you put in place at the start and unit test aspects as you need to?<p>Also, you mentioned changes to the API of third-party libraries. How do go about catching how those changes impact your code? (I would assume you are mocking these in your unit tests.)<p>Wow I just asked you a lot of questions.<p>Seriously though, thanks for posting this article. It's so rare to be able to read an article about unit testing that isn't just some guy demonstrating how he'd use TDD to determine if a number is in the Fibonacci sequence or something.
评论 #1842793 未加载
评论 #1842758 未加载
felixgeover 14 years ago
A few facts that I didn't get to fit into the article:<p>- We have ~1.6x as much test code as we have code being tested.<p>- Our unit test suite takes &#60; 5 seconds to run. Our system test suite takes &#60; 60 seconds.<p>- We use Hudson for continuous integration<p>- The hardest part with TDD for us was reaching 1.0 as you always feel like it would be "faster" to stop testing.<p>- We usually don't go around refactoring stuff just because we can. In fact we usually feel more confident building upon existing stuff since we have tests that are saying it works.<p>And it goes without saying, feel free to ask me anything : ).
评论 #1842679 未加载
ericbover 14 years ago
Test driven development, to me, starts as the harness you use to write your code in the first place. I'm not sure how people write solid code with any kind of speed without a harness testing/driving it. Why not make your harness your tests?<p>Everyone keeps talking about how it is more work, which confuses me. I don't make a religion out of test coverage, so maybe that is the difference? As in, I don't write a test for every basic thing, like an accessor, for example, because I feel like there's a point of diminishing returns.<p>edit: To those downvoting, I'm interested in a dialogue and hearing your thoughts.
评论 #1842731 未加载
评论 #1842715 未加载
ollysbover 14 years ago
One of the most pleasurable benefits of TDD is that I can refactor code and not worry that I'm going to break something. On larger projects this is really liberating, I can develop with the same freedom that I did on day 1. It means that a code base can evolve smoothly and naturally, assimilating new requirements. Without that safety net you end up with code that gradually becomes a poorer fit for the requirements, changes becoming huge snaps as they are delayed over the fear of regressions.
评论 #1843237 未加载
评论 #1843381 未加载
DanielBMarkhamover 14 years ago
I'm extremely happy to upvote first-hand TDD articles whenever I see them on here.<p>There have been quite a few nice stories, both pro and con. I'd like to see more folks talk about competitive advantage. After all, code just doesn't exist by itself -- it's supposed to <i>do something</i>. Does TDD help make technology make people's lives better? Or is it just a big PITA that ends up with more maintainable code? There's nothing wrong with that, but it's the kind of perspective question can be a critical success factor for startups.
评论 #1843346 未加载
评论 #1842826 未加载
ericHosickover 14 years ago
I think it would also behoove you to start using BDD in your development process. With BDD, you get a one-to-many correlation between behavior and code. This also greatly improves on quality. I say this because quality can only be based against requirements. BDD forces the developer to have the behavioral requirements upfront.<p>BDD allows you to take a given behavioral requirement and see all the code that supports that requirement and visa-versa. If a customer ever asks you, you can point to exactly where you are fulfilling that behavioral requirement in the source code.<p>And BDD languages such as Gherkin are easy to read for most non-technical people.<p>Of course, this isn't a replacement for TDD.
评论 #1842759 未加载
评论 #1843072 未加载
评论 #1842835 未加载
olliesaundersover 14 years ago
John Hughes, (author of Why FP Matter) is mitigating some of the problems of TDD with QuickCheck (<a href="http://en.wikipedia.org/wiki/QuickCheck" rel="nofollow">http://en.wikipedia.org/wiki/QuickCheck</a>).<p>Video: <a href="http://www.infoq.com/presentations/The-Joy-of-Testing" rel="nofollow">http://www.infoq.com/presentations/The-Joy-of-Testing</a><p>I've been using it for the last couple of days. You'll have to excuse not being able to see the demo properly. InfoQ fail. Stick with it, there's some really cool stuff at the end.<p>Another video: <a href="http://video.google.com/videoplay?docid=4655369445141008672#" rel="nofollow">http://video.google.com/videoplay?docid=4655369445141008672#</a>
Tomek_over 14 years ago
Until recently I was looking at TDD as a necessary evil - yes, it saves your ass a lot of times, but writing tests doesn't feel fun nor very productive - I don't know if I can speak for others, but for myself there are two things that I like most in programming, 1st: creating cool, new features; 2nd: polishing/refactoring the code until it becomes a state of art.<p>And what I've found out not a long time ago is that TDD helps <i>a lot</i> with the 2nd point, but only (again, at least for me) if you aim for the 100% code coverage. Yes, I know it sounds silly, and pointless, and that code coverage doesn't mean that much, but anything lower than those 100% makes you too relaxed about quality of the code and leads to skipping the parts that are harder to test, and most often they are hard to test because they are badly written (bad architecture, bad API decisions, etc.).<p>When you go for a 100% CC you have to examine all those parts, and change the code so it actually can become testable, and it's often hard and requires making big changes in many places. It's challenging, but challenging means fun. And you learn a lot, but learning a lot is fun too. So, double win (triple, if you count easier bugspotting)!
omouseover 14 years ago
<i>Writing those tests feels like proofing mathematical theorems</i><p>Uh, not really. Have you ever written tests for functions in math? It's a pain in the ass once you get past 5 variables. This is why we have proofs in the first place, to prove that something is true for each and every case without having to run through every test...
johnwatson11218over 14 years ago
I really like the author's assertion that writing the test feels like proving mathematics. I have always been fascinated by this connection. When you look at the history of mathematics w/r/t the discovery of calculus there was a 150+ year period in which people could use it to do work but nobody could prove calculus. It wasn't until the early 1800s and the technique involved bounding errors. I'm referring to the delta-epsilon proofs from analysis. To me this is <i>exactly</i> like what is happening in computer programming right now. In my opinion automated testing is some of the most cutting edge stuff going on right now.
steilpassover 14 years ago
BTW Felix was interviewed about Node.js at <a href="http://chaosradio.ccc.de/cre167.html" rel="nofollow">http://chaosradio.ccc.de/cre167.html</a> (German)
Ixiausover 14 years ago
I'm building a startup with Python and Pylons - Pylons comes with paster (python web server) and a small unit testing hook for your app; pylons makes it so <i>easy</i> to test your application, I love it. You can write two types of tests: functional tests and unit tests.<p>I split functional tests into the tests that actually make a web request (by spawning paster, loading the application, and pretending to be a user) - my lowest "unit" there are my controllers. I have to have some special trickery to handle sessions, but it isn't bad, beats having no tests.<p>My "unit" tests are a bit less fine-grained than yours are. I've had difficulty narrowing tests down below the module level with anything but libraries; primarily because models (the culprits here) have a few interdependencies. I do my best to keep my models orthogonal but not all of them are, so most of my unit tests are basically testing models as they operate on the database tables and some of their assistant methods.<p>If I write a library, I generally try to determine whether it can be its own "module" or should be a module within the application namespace. For example, I wrote an authorize.net payment library and ultimately decided that it should have its own tests - separate from the application, which lead me to splitting it off as its own project (PayPy now, with adapter support for some other gateways). Writing some of the library modules in their own namespace with their own tests keeps it clean orthogonal.<p>Overall, I would say this: I'm not as OCD about writing tests as you are because I'm the sole developer and there are too many features to build to be writing functional tests every time I build a controller. My philosophy is this, though: the models should <i>all</i> be covered, no matter what; since they are the messiest bit of logic (usually) in a web application - translation between <i>relational</i> data into <i>object oriented</i> data has a lot of side effects. Having all models covered ensures that the majority of my logic that interacts with the database is solid. It also keeps any schema/model changes in check that may affect other models I've forgotten about.<p>After that, I try to make sure any <i>critical</i> controllers/pages/functional pieces are covered - the really trivial stuff I worry less about and just make sure it "works right" by doing some manual testing myself before pushing it.<p>I love functional/unit testing - I will never go back. My old way of development feels like I was lost in the dark ages of my career or something...
daloreover 14 years ago
Is it really a unit test if you make a call to a REST service? Is that not now an integration test?
评论 #1843239 未加载
sreuterover 14 years ago
nice one!