TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: What resource do you recommend to start with Test Driven Development?

11 点作者 rednosehacker超过 4 年前

6 条评论

Normille超过 4 年前
I&#x27;ve never been able to get my head round the concept of Test Driven Development. Maybe it&#x27;s because, every time I&#x27;ve seen an example of it [which, like the one you linked to] are usually aimed at explaining the concept, they seem like a lot of extra work for questionable benefit.<p>For example: I&#x27;ve got some &#x27;multiplying&#x27; code that should return 4 when passed 2 and 2 so I&#x27;m advised to write an &quot;assert&quot; test that returns 4 when I send it 2 and 2. But what happens if I send it just 2?... or 2 and 2 and 2?... or 2 and 3?... or 2 and W? None of the examples of why it&#x27;s so vital to write tests ever seem to cover this kind of thing? They just seem to show a test which returns the correct answer when given the correct data. But aren&#x27;t many of the problems with software caused when a piece of code receives the wrong data in the first place?<p>Genuine question. I&#x27;ve read so many times about why I should practice TDD that I believe it in theory. But I&#x27;ve never seen a beginner&#x27;s example that has actually seemed like it would provide the claimed benefits. Why is writing a test that takes one single specified input and checks for one single specified output &quot;better&quot; than just writing my code and then trying to break it by [metaphorically] hitting the &quot;Do Not Press!&quot; button, by throwing as much incorrect, malformed or otherwise &quot;wrong&quot; data at it, as possible.
评论 #24314488 未加载
评论 #24303563 未加载
chris_j超过 4 年前
TDD by Jason Gorman is a nice (and free) introduction: <a href="http:&#x2F;&#x2F;codemanship.co.uk&#x2F;tdd_jasongorman_codemanship.pdf" rel="nofollow">http:&#x2F;&#x2F;codemanship.co.uk&#x2F;tdd_jasongorman_codemanship.pdf</a> (disclosure: I did Jason&#x27;s ~TDD training course a number of years ago and gained a lot from it - but the book is useful on its own).<p>A book that explains TDD in the context of a much larger example application is Growing Object-Oriented Software, Guided by Tests by Steve Freeman, Nat Pryce (sometimes referred to as &quot;The GOOS Book&quot;).<p>One of the difficult things about TDD is that it takes a long time to learn to do it effectively. I personally didn&#x27;t really &quot;get&quot; TDD until I paired with a few much more experienced developers, and this forced me to rethink the way that I approached writing software. Ultimately, it caused me to significantly level up my coding skills and I wouldn&#x27;t go back to the way that I used to write code before.
评论 #24329058 未加载
moksly超过 4 年前
I’d recommend you stop, but if you’re really going to go through with it. One of the best resources is the testing goat book. It’s tool specific (django&#x2F;python) but it’s so good I think it’s worth it just to get into the subject.<p><a href="https:&#x2F;&#x2F;www.obeythetestinggoat.com&#x2F;pages&#x2F;book.html#toc" rel="nofollow">https:&#x2F;&#x2F;www.obeythetestinggoat.com&#x2F;pages&#x2F;book.html#toc</a>
tmaly超过 4 年前
I would highly recommend reading Kent Beck&#x27;s book. He walks you through the entire process. He has two examples, one in Java and one in Python. Both are readable even if you do not program in either language.
bitfield超过 4 年前
You could try <a href="https:&#x2F;&#x2F;github.com&#x2F;bitfield&#x2F;ftl-fundamentals" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bitfield&#x2F;ftl-fundamentals</a>
评论 #24303085 未加载
sloopy543超过 4 年前
None! Don&#x27;t do it! It&#x27;s a foolish and dogmatic way to make software, and a waste of time.
评论 #24306958 未加载