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.

Against Testing

172 pointsby amatheusalmost 5 years ago

68 comments

ricticalmost 5 years ago
Software engineering is programming over time. It&#x27;s not so hard to write code that is correct today, if that&#x27;s all that tests did then they wouldn&#x27;t be worth the effort.<p>We write tests so that we know whether future changes have broken the system or not.<p>This article sounds like a reaction to the practice of writing many small, hermetic unit tests, which do little more than recapitulate the code under test. The weakest parts of a system are often in the joints, so the most important tests to write and to run are the integration tests, the ones that tell you with the most confidence whether the code works in the real world or not.<p>See, for example, this puzzling line from the article:<p>&gt; Other tests grow obsolete because the target platform is retired, but not the test. There&#x27;s even less pressure to remove stale tests than useless code. Watch as the workaround for Windows XP is removed from the code, but not the test checking it still works.<p>How do you remove the code for a feature, but not the test for that feature unless either you aren&#x27;t running your tests or your tests aren&#x27;t testing the things that you care about?
评论 #23756846 未加载
评论 #23757069 未加载
评论 #23757233 未加载
评论 #23757007 未加载
评论 #23758893 未加载
评论 #23756866 未加载
jchwalmost 5 years ago
Aside from everything else, writing tests is just as much about writing testable code. Not everything that makes code easier to test makes code better, but often times many things do; after all, nothing is easier to test than a simple, small, pure function with inputs and outputs.<p>I prefer trying to focus on table driven testing where I can write a single test that exercises the code various ways. This is not applicable to all types of software, but it is wonderful for things like parsers, emitters, algorithms, data structures... things that test well.<p>Unit tests like this are cheap but make it easy to assert that the code works. If you can assert that your individual functions do what you expect, it makes debugging and understanding software easier.<p>I like to think of testing as executable debugging. It’s like a debugging session that is executed over and over again. If your tests are difficult to maintain it may say something about what they are asserting or what they are testing.
评论 #23757141 未加载
评论 #23759301 未加载
评论 #23755848 未加载
bArrayalmost 5 years ago
For Testing:<p>1. Tests aren&#x27;t necessarily for you, they could be to convince somebody else that your solution is robust enough to be used for their use-cases.<p>2. Test&#x27;s aren&#x27;t necessarily for today. They could be about preventing code regression in the future (some dev comes in and makes &quot;performance&quot; changes for example, not realizing they are breaking the code for others).<p>3. They can be about testing that the code behaves how you believe it behaves. Sometimes even simple code requires a sanity check.<p>4. 100% test coverage is likely impossible, but if we do find errors, we can learn from them and try to prevent them happening in the future by adding them to the tests.<p>5. Tests breaking are a good thing. They inform you that some change you are making is changing the behavior of something you thought to be act reliably.<p>6. With regards to the same mind making the tests, this could also be a useful tool for ensuring a developer of some code thought of most the edge cases when merging some code. &quot;Ah, i see you didn&#x27;t add minus numbers to the tests, how are those handled?&quot;<p>7. We should be able to freely rip out tests and add testing as the requirements of the code base change. Generally though, the goal of much code doesn&#x27;t really change, despite perhaps how exactly it achieves the task does.
评论 #23761242 未加载
Netcobalmost 5 years ago
Two harmful ideas I got out of university: Tests must absolutely cover as much code as possible and if something cannot be solved perfectly then any solution is wrong and useless.<p>I doubt that this was the intention or that anyone there teaching actually thought that, but the way things were taught to us we ended up thinking we had to test every single getter and setter. And that the traveling salesperson problem is essentially unsolvable because no efficient algorithm exists.<p>With a tiny bit more nuance you then find out that how much testing is useful depends on the domain&#x2F;industry quite a lot, and that there are usually plenty of &quot;good enough&quot; solutions to seemingly impossible problems. Sweeping, extreme generalizations are for the inexperienced.<p>I love integration tests. You can specify your use cases right there in the code (maybe link to some official document), and often you are basically writing usage examples for your API so that someone new to the code can go straight to the tests to get a nice overview over how it&#x27;s used. Regression tests can save you from looking like an idiot. I&#x27;m not going to pretend that testing is on the same level as something like formal verification, but as long as you don&#x27;t overdo it I think it still has a lot of value.
chriswarboalmost 5 years ago
It&#x27;s important to remember that our own mental model is a very important part of any project. I&#x27;ve often read complaints about people tracking down a test failure and finding out it&#x27;s actually a problem with the test and not the implementation, as if that were a waste of time. However, we need to ask the question: why did someone write that test, and do it in that way? If the answer is &quot;because they didn&#x27;t understand how the system works&quot; then we&#x27;ve just exposed a bug in someone&#x27;s mental model (often our own). It&#x27;s not a waste of time to find and fix these failures (either by changing the test, now that we&#x27;ve improved our understanding of the system; or by removing it as superfluous). The article&#x27;s example of checking for the round-robin algorithm rather than a lack of race conditions seems like one of these cases.<p>Of course, this isn&#x27;t the only reason why supposedly-spurious test failures occur. If the answer to &quot;why did someone write this test in this way?&quot; is something like &quot;to increase code coverage&quot; or &quot;they watched a talk that said to do things this way&quot; or something equally silly then that&#x27;s harder to spin as a positive. Hopefully it might at least expose failures in those development practices?<p>Unfortunately the developer who has to fix these failures is often someone who already understands, and wouldn&#x27;t have written the test that way. Perhaps it&#x27;s exposing a problem in their documentation, coding guidelines, etc.?
rooam-devalmost 5 years ago
I couldn&#x27;t tell if this is a joke or for real.<p>My 2 cents regarding testing. Written tests have 2 goals, 1: help to build your code (you verify your code as you write it). 2: Regression testing (new changes have less chances to break your code).<p>We as devs need to hand over&#x2F;deploy a verified code. Without tests this means manual testing, without manual testing means not verified code. Manual testing means slow development process.<p>It&#x27;s 2020, I think we have more time writing tests than before with all those cool IDEs, tools, frameworks. No tests means laziness and&#x2F;or cockiness. Imho of course.
评论 #23756922 未加载
评论 #23758266 未加载
tomlagieralmost 5 years ago
One strategy that I&#x27;m really enjoying at a current gig: have the person writing the front-end write the end-to-end tests (or at least the specs) for the person writing the back-end. Just having a fresh set of eyes on the tests has flushed out a lot of edge cases, and tests make a perfect place to iron out small behavioral details. It really solves the &quot;same mind writing the code and tests&quot; issue.<p>Of course, this isn&#x27;t always feasible (and is a little unfair to the frontend person in terms of workload).
评论 #23755883 未加载
diobalmost 5 years ago
Well written tests make refactoring a breeze.<p>Poorly written tests make refactoring nigh impossible, and usually don&#x27;t contribute to anything other than code coverage metrics.<p>Focus on quality, not quantity.
评论 #23755922 未加载
评论 #23755818 未加载
评论 #23759173 未加载
评论 #23756272 未加载
postalratalmost 5 years ago
I feel in a few years people will look back and laugh at all the useless tests we wrote.<p>I still haven&#x27;t seen a test that can prove even an identity function is correct. Yet it&#x27;s obvious to the programmer.<p>We lack the technology to properly test software. I like to think tests are a way to implement twice and hope you got it right at least once. But we aren&#x27;t even to that point yet.
评论 #23755928 未加载
评论 #23756002 未加载
评论 #23758558 未加载
评论 #23757667 未加载
评论 #23756772 未加载
评论 #23757203 未加载
评论 #23755982 未加载
评论 #23756875 未加载
评论 #23758676 未加载
grink71almost 5 years ago
One benefit of testing I haven&#x27;t seen much discussed yet is that testing can make <i>fixing</i> bugs easier. Many times in my career, there was a bug reported in a function I am not familiar with, based on a very particular set of conditions. There is a lot of work required to simply recreate the conditions that will allow me to debug. If I have written a test, where I have created appropriate fixtures and isolated the logic, I can easily recreate the failure condition and find where my logic is broken.
rooam-devalmost 5 years ago
Personal experience is great, but facts are more important.<p>IBM team did 40% fewer defects than non-TDD team, Microsoft team: 60–90% (fewer defects than non-TDD fellows).<p>You can read more here: <a href="https:&#x2F;&#x2F;medium.com&#x2F;crowdbotics&#x2F;tdd-roi-is-test-driven-development-worth-the-money-d535c8d5a5f" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;crowdbotics&#x2F;tdd-roi-is-test-driven-develo...</a>
评论 #23763952 未加载
评论 #23760724 未加载
评论 #23760059 未加载
myspyalmost 5 years ago
Starting your implementation with a test that&#x27;s setting up, what the expected result is, and then implementing the controllers&#x2F;whatever against that test is pretty satisfying.<p>In web development it also makes back-end development faster. Switching to a browser, reloading the page and inspecting the console&#x2F;properties&#x2F;page, is so slow.<p>I wasn&#x27;t really into testing until a certain point, but having the confidence that your business logic still works after doing change requests is a bliss.<p>No testing it in the browser, no testing it with postman, no checking if mails are send in your dummy smtp server interface etc.<p>When you don&#x27;t write software that changes very often or has many use cases, go ahead and leave them out, but the more you take on your shoulders, the better automating the tedious work.
staredalmost 5 years ago
Again, there is a misconception that test prove that a given module works. No, they don&#x27;t.<p>Test may serve as some kind of &quot;persistent REPL&quot; to make sure you didn&#x27;t miss some edge case. But, at least to me, the real value of tests is confidence for refactoring.<p>Otherwise it is so easy to &quot;simplify&quot; a function but break code due to some implicit type cast, or making it work only for positive values, etc.
alephu5almost 5 years ago
I work on a codebase full of crappy unit tests that require more maintenance than the software itself. There&#x27;s even a test that asserts the dockerfile matches a particular regex. It&#x27;s made me realise that you should only encode your specifications in the tests, i.e check that all documented features work and that it fails gracefully outside this range. Some may not even be full end-end tests, you just have to be sensible and make them as high-level as feasible.
ilyanepalmost 5 years ago
It seems to me that someone with this philosophy has never tried to change or refactor a subsystem of a very complicated legacy project. Sure, sometimes your tests fail because they&#x27;re poorly written and test implementation details, but other times they catch the fact that you didn&#x27;t know about case X that had been discovered years ago and required a minor non-obvious tweak in the code to make work correctly.
kalyantmalmost 5 years ago
I kinda agree with the core issue here: Writing small, hermetic unit tests wont get you far, but unit tests themselves get you only so far. As Kent C Dodds puts it, Write few tests, mostly integration. That immediately sat with me. When u model tests based on how your software is supposed to interact, I see instant gains, i&#x27;m more confident about the code and have refactored parts of it as well.
aazaaalmost 5 years ago
The article doesn&#x27;t mention refactoring, and that&#x27;s where the value of tests lies.<p>Given a complete test suite and stable interfaces, you can make substantial changes to existing code and if you break anything you&#x27;ll know. It&#x27;s often the difference between making changes that need to be made, and avoiding those changes because there&#x27;s no safety net.<p>I&#x27;d be curious how the author approaches refactoring.
jasonlfunkalmost 5 years ago
&gt; One way I like to consider this is to look back after a bug is found, and ask how many tests would have been needed to detect it. The minimal answer is of course one, but we can&#x27;t reasonably believe that this exact test would be the next one added.<p>No, you can&#x27;t. That&#x27;s why when the bug occurs, you can add that test and then that bug never happens again.
lattalaytaalmost 5 years ago
I&#x27;m curious what kind of programs the author is writing (and not testing) here.<p>A few years ago, I implemented tests in a Django website I manage on the side, and am around 90%+ &quot;coverage&quot;. Since then, I&#x27;ve been able to upgrade major&#x2F;minor versions, add new features, and have deployed around 100 updates. Automated testing before deploying has caught numerous small typos and errors before anything went live.<p>On the other hand, I&#x27;m also writing some games right now, and those don&#x27;t have any tests. I can&#x27;t see as clear of a reason to implement them.<p>Would others agree that certain areas of dev are more suited for testing than others?
评论 #23757756 未加载
评论 #23757362 未加载
lmmalmost 5 years ago
The author should put this into context of the language being used. In languages with poor separation of interface and implementation, and limited datastructure support, tests do indeed tend to be bad. That&#x27;s less a fact about testing and more a fact about those languages.
thinkingemotealmost 5 years ago
Tests should fail often. We don&#x27;t want tests to fail but we should!<p>We almost always write tests so that they pass - we should write tests so that if someone makes some change in the future that they fail easily.<p>Tests should be an aid, they should give you the heads up that something happened. They should be flags to help you not a game of achievement or failure.<p>We should call them traps. We make traps in code to trap bugs. Psychologically you can view them as games but avoid the negative connotations of failure.
评论 #23757563 未加载
pnakoalmost 5 years ago
You cannot possibly avoid testing software, unless the software is literally useless.<p>So testing will definitely happen _at some point_. The debate is about where it happens: on the developer&#x27;s computer, on a tester&#x27;s computer, on a CI agent, or on the user&#x27;s computer.<p>I like to cover as much code as possible before the software reaches the user, but that&#x27;s just me.
rkangelalmost 5 years ago
I have to opposing thoughts on this subject.<p>I find that two many unit tests actually result in worse architected code as refactoring takes (at least) twice as long as you have to refactor the tests too. This can be mitigated a lot by seeing your tests also as code that needs to be architected well (shared code refactored out) but it is still a problem.<p>The flip side though is when you are writing code that is difficult or time consuming to get running. I am the lead for a telecomms system, the whole setup to get the code running requires hardware, signal generators and spectrum analysers. We have all that available on remote access but it can take time and fiddling for each code iteration. If I instead write automated tests at a couple of levels I can write a lot of code with confidence and then integrate with (i.e. test on) the hardware at the end with low risk of finding issues.
mpweiheralmost 5 years ago
The article sounds very much like the author is writing tests after, so writing tests <i>for the code already written</i>.<p>I had very similar experience when writing tests after.<p>And it turned around completely when I started writing tests first.<p>Now the tests are not aiming at specific properties of the code, nor are they duplicating the thought patterns in the code. They are simply examples of what the code should do, and as such are documentation and formal&#x2F;informal specification. Formal in that code is a formal system, informal in that they aren&#x27;t actually trying to be a complete specification.<p>So if you&#x27;re suffering the same symptoms as the author, I suggest you try test first, it&#x27;s a world of difference.<p>(And of course all the comments about safety for refactoring, programming over time etc.)
bobmaxupalmost 5 years ago
There are probably hundreds of thousands of pages that have been published on this subject. Is there anything to be gained by reading these month-to-month anti-testing articles that consist of 10 paragraphs of enlightenment?
评论 #23759511 未加载
djohnstonalmost 5 years ago
&gt; Tests are very brittle, breaking due to entirely innocuous changes in the code because they inadvertently embed very specific implementation dependencies. Test for a race condition? Actually a test of the scheduler&#x27;s round robin algorithm.<p>This matches my professional experience with writing and maintaining unit tests. They are often coded to the impl and are basically worthless IMO. I think you generally can get more bang for your buck with higher level functional tests, i.e., does this change preserve the functionality of the critical paths in an e2e flow?
renke1almost 5 years ago
Integration tests can outlive refactorings. Unit tests rarely do. Delete your unit tests after your integration tests pass. At least those unit tests that heavily rely on stubbing.
exdsqalmost 5 years ago
Property based testing would blow this persons mind, so many of these issues are resolved by them.
jeffmcmahanalmost 5 years ago
Everything in this article is correct except the conclusion that it&#x27;s better not to write tests. Testing is an artform all its own. I find two tricks indispensable.<p>First I declare a &quot;foo.src.js&quot; file to hold a module&#x27;s logic, and then a test file as &quot;foo.js&quot; and have the test file import the logic and then export whatever is to be public. Client code imports the test file and <i>not</i> the source file, so the tests sit in between the logic and the client code, as it were. No more balancing testability against encapsulation.<p>The second is indirection. I create a mockability decorator. Then have a function (I call it &#x27;mock&#x27;) which can be used to temporarily redefine any function declared mockable, and then switch back to the real thing when the current test is through. So I get:<p><pre><code> const readFile = mockable(fs.promises.readFile) ... mock(readFile)(async () =&gt; &#x27;mock file contents&#x27;) </code></pre> Combining these approaches doesn&#x27;t so much prevent rework on tests when code changes as it makes it <i>much</i> less trouble to implement tests for 98% of cases.
评论 #23756084 未加载
runawaybottlealmost 5 years ago
Here’s one thing test driven development solves that has nothing to do with testing - empathetic code. Soon as you force people to write testable pieces of code, by definition you just forced them to write a good interface that considers how others will&#x2F;could use it (in this case the ‘other’ is a test suite).<p>When that’s not in place, people often create selfish code where only their own needs are addressed.
cafalmost 5 years ago
Regression tests get around a lot of these drawbacks: they cover edge cases that have already been shown to have been overlooked in the past; and they&#x27;re not unnecessarily brittle or testing things that might legitimately change because they&#x27;re testing something that we know someone has relied on in the past.<p>They can still end up platform (or more generally, environment) specific, though.
ramtatatamalmost 5 years ago
Author writes &#x27;In order to be effective, a test needs to exist for some condition not handled by the code.&#x27;<p>I think he is missing the point. In tests I write I capture what users do so I can gain some trust before releasing new code, that old still behaves the same way. I also often debug my new code by writing tests, especially on systems where I cannot just run my code against.
agentultraalmost 5 years ago
This sounds like the article should be <i>against brittle testing</i>.<p>If any of the following is true then you&#x27;re writing brittle tests:<p>- <i>Your test code looks like the code under test</i><p>- <i>Your test suite includes examples that tweak one parameter and assert a result</i><p>- <i>Your tests pass when you delete an arbitrary line of code from the implementation</i><p>I can&#x27;t imagine shipping any significant project without any tests. How would I know that what I wrote implements my specifications faithfully? Hand waving and trust?<p>Unit tests are proof by example. They&#x27;re trivial and don&#x27;t prove the absence of errors. So I use them sparingly for simple, pure code where a few assumptions are enough.<p><i>Property</i> tests are where I spend more of my time and focus. I generate the tests from a specification of a property I want to ensure will hold. It&#x27;s not a formal proof that there are no errors but if my code survives 500 generated test cases and I have a good distribution over expected and hostile input I can be satisfied that my code is correct.<p>I don&#x27;t spend time writing unit tests for effectful code. If I have business logic that is tied up calling a lot of APIs and digging into databases I <i>defunctionalize</i> the effect handling code and write interpreters for the data structures instead so that testing is still pure and easy and the effect handling code is constrained and found in one place. I test the pure version to makes sure the interpreter receives the correct sequence of data.<p>Sometimes I will use <i>gold</i> tests for serialization code. If I need to make sure that a contract I have with an external system isn&#x27;t broken by my changes to the code I make sure to run the tests that will check what gets serialized out matches up with the golden examples.<p>If I need to ensure certain temporal properties hold like resource usage and performance... well I&#x27;ll need regression and load tests.<p>These are all a part of the development process. You can ship code with no tests but good luck refactoring, maintaining, fixing, and understanding that code a year from now. It&#x27;s possible, don&#x27;t get me wrong, but it takes extreme discipline and even then that sometimes fails. People get tired, leave, get bored, etc. Having the computer check for you that everything is still working as expected is essential in my books.
clktmralmost 5 years ago
I have seen too many badly written tests, so I tend to agree. Most tests will just fail on any change in the UUT, giving you lots of false positives. This ultimately results in fixing the tests instead of the UUT and blurring the initial intention of the test.<p>Writing testable code is not about dependency injection etc. It&#x27;s about having the behaviour of a unit clearly defined. This can be done explicitly in text, but also implicitly by using the component in a certain way. If anything beyond that behaviour is tested, you start to defining the behavior in the testcase. This is fine, but often happens unintentionally leading to a very weird and very specific definition of the behaviour.<p>For example, I work on a component that generates a configuration. I know that the order of lines of the output doesn&#x27;t matter and should not matter. But the initial author wrote tests that fail if the order changes, because they just check the output against a string.
评论 #23757467 未加载
msclrhdalmost 5 years ago
If you are implementing a specification (e.g. CSS&#x2F;HTML&#x2F;other language parser), tests are invaluable to assess how conformant your code is. They allow you to test the different parts and specifications in isolation (the lexer, the parser, the value&#x2F;unit handling, etc.)<p>If you are implementing interfaces that plug into some other program (e.g. an IDE, or even different teams in a project), tests are invaluable to check that your code works as expected, and does not break when a new version of the program is released.<p>Yes, writing tests takes longer. Yes, writing tests makes it harder to change the code in the future. However, they have helped me identify cases in my code that I had not considered (when integrating my code with an IDE), and to prevent issues when refactoring and extending the code.<p>There are ways to mitigate the issues of changing the code, such as creating scaffolding to bridge the old and new code via adaptors, etc.
flr03almost 5 years ago
I mean this looks like the author is just trying to find a justification to not write unit tests because he doesn&#x27;t like it.<p>I pick the last sentence &quot;If you like writing tests and are very good at it, you may continue to do so.&quot; This basically means, well &quot;I don&#x27;t like it, I&#x27;m not very good at it so I won&#x27;t do it&quot;.<p>What I want to answer to that is that if you are not good at it, spend time to get better. Everyone can learn what is a unit test in 5 mins, writing good tests and good testable code takes years. Do tests get deprecated and useless, are they hard to maintain? Yes that&#x27;s right, this happens. So don&#x27;t aim for any coverage percentage, if you aim for 80% coverage but the last 30% are a pain to write, a pain to maintain and don&#x27;t bring a lot a value then don&#x27;t write them. Focus on the rest, make sure the core functionalities are well covered.
monksyalmost 5 years ago
A few things about where this guy is wrong on the definitions. For testing there are:<p>Unit Tests - This is usually per method and on a disconnected basis (you don&#x27;t have a direct call to a resource on this)<p>Integrations - this is a combination of other unit tests. May use stubs and or mocks to isolate the external resources involved.<p>Functional&#x2F;feature- This is where you get embedded services involved<p>Product acceptance test - This tends to test the individual application from deployment to running. This tends to verify outward features with live resources behind it. (Pipeline - it&#x27;s one piece of the pipeline running live)<p>System test - this is where you can get live test environments setup and prepped for it. This tends to test the system as a whole (Pipeline- it&#x27;s the entire pipeline in a test environment) Usual definitions are:<p>Smoke test - a briefer test of the System test.. but meant to prove out things work. Doesn&#x27;t verify
maitredusoialmost 5 years ago
I, 100% agree, tests should be automatly made.<p>When I am on a ruby console and I test manually, I should be able to create a test that will replicate the one done by hand. I should not have to learn a test framework.<p>For all for reasons I decided to only test real edge cases. Also I have now to create that magical gem that will generate automatly test.
neallindsayalmost 5 years ago
The author imagines that the value of tests would be to detect errors the developer does not know about as they initially write the code. They are understandably skeptical that tests can provide that kind of value.<p>In my experience, the &quot;error detecting&quot; value that a test sometimes gives you only occurs when you revisit code. Preventing regressions is very nice, but this is still not the main value of tests.<p>The real benefit of writing tests comes when you write them before you write any production code. That way the tests give you feedback about your software design. Code that is difficult to test is also difficult to use correctly.<p>They also complain about the friction you feel when you want to change behavior, but tests require the existing behavior. In this case the test should be changed or deleted. People are often too hesitant to delete tests.
SeriousMalmost 5 years ago
Writing tests help to design the code to be accessible and being modular. I test the vanilla paths of our software to ensure that refactorings don&#x27;t break the business. I could go far deeper and explain every little detail but this is the most important thing about testing.
georgelyonalmost 5 years ago
I very much agree with this sentiment, but it is difficult to endorse this line of reasoning without offering a better alternative. As folks have pointed out in other comments, there are other values to tests in the broad sense that the author doesn’t address. That said, if you are interested in improving the state of testing, I would encourage you to listen to Will Wilson’s excellent talk on the subject of Autonomous Testing: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=fFSPwJFXVlw" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=fFSPwJFXVlw</a> Indeed, FoundationDB (which Wilson worked on) has a very unique and sophisticated approach to testing that seems to have served them very well.
CobrastanJorjialmost 5 years ago
The title&#x27;s a bit sensational. Yes, bad tests are bad. But nobody&#x27;s entirely against testing in every situation.<p>Imagine that you&#x27;re Microsoft, except you&#x27;re against testing. You decide to refactor some Windows XP source a bit. What now? Just compile it and ship the result without even trying to boot it once?<p>Clearly that&#x27;s unacceptable, so at least some testing must be okay in at least some scenarios. The question is how much and when. One or two black box tests of your program can get you a long way. Add more as needed to gain whatever degree of confidence is necessary. Remove tests that are redundant, fragile, or just exist reflexively because &quot;code needs tests.&quot;
alkonautalmost 5 years ago
How does one even modify anything nontrivial without a test harness? You’d need to understand and remember every edge case in the whole system?<p>Take a nontrivial (but by no means enormous nor “messy”) system like the Roslyn C# compiler. It’s developed to a formal spec which is extremely rare, but it’s likeky almost impossible to add e.g a syntax change and foresee how that affects all scenarios. I can guarantee that any nontrivial change will break some tests which will force the author to iterate and solve the issues.<p>Most systems you encounter will be older, many will be much larger, messier, and not have the luxury of a spec that Roslyn has.
xupybdalmost 5 years ago
I worked on a legacy system that had no tests for years. Just as I left tests were slowly added. The project went from a painful quagmire to a maintainable code base in months. The transformation was unbelievable.
Koshkinalmost 5 years ago
A general problem with writing tests as it is usually done now is that tests are written by those who wrote code being tested. Writing tests is a professional activity in its own right and requires special skills. (This is how companies like IBM used to work back in the day.) Sure, programmers want to do sanity checks on code they write, but this by no means should amount to testing in the proper sense, nor do you want to force coders to waste their expensive time on something that is not 1) generating ideas and 2) writing <i>new</i> code.
jerome-jhalmost 5 years ago
I always test till I find at least one bug. This approach has never failed me, and I usually find more than one. Sometimes its a corner case but still a condition the software should handle. I would really have to write a very tiny thing in order not to make a single bug!<p>Of course archiving the tests can be a pain if nothing is prepared for it. Automating the tests is yet another pain. Still I worked on a library once when I added quite a few automated tests, because the infra was basically there and just waiting for it.
ChrisMarshallNYalmost 5 years ago
Sounds like this is aimed mostly at unit tests, and the way we tend to roll testing into CI&#x2F;D.<p>I prefer test harnesses and “monkey testing.”<p>I write about that, here: <a href="https:&#x2F;&#x2F;medium.com&#x2F;chrismarshallny&#x2F;testing-harness-vs-unit-498766c499aa" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;chrismarshallny&#x2F;testing-harness-vs-unit-4...</a><p>But I am REAL BIG on testing. Yeah, it ain’t fun, but I’ve been writing shipping software for most of my adult life, and, in my experience, about 60% of ship is boring stuff.
vmceptionalmost 5 years ago
I used to be like this person, but then my testing suite got so gamified that I really loved getting all the checkmarks on files, all the functions covered, writing functions in ways they could be covered, and moving the percentage to max coverage!<p>I also really did become a better programmer from them too. I used to think I knew what all the functions did and their requirements, but tests would often show me how a case a failed.<p>And of course if anything changes the test reveals this too.
SPBSalmost 5 years ago
This is why integration tests are more valuable than unit tests. Integration tests directly test the desired output, no need to think about what to test. Integration tests flag if something is wrong, unit tests help refine which part is wrong. If all integration tests are consistently passing I honestly do not see the value in having to write unit tests as well (or at the very least they have lower priority).
raxxorraxalmost 5 years ago
While it is true that the author is saying, tests provide a mechanism to check if your code behaves in a different way than before if some tests suddenly stop working. That is different than a proof that you software doesn&#x27;t contain bugs.<p>I would love to have a decent solutions for unit tests on embedded systems with &quot;bare-metal&quot; firmware. There are some approaches, but the situation is certainly not optimal.
wallfaceralmost 5 years ago
“There&#x27;s some amount of discomfort I&#x27;d be willing to sustain if I felt it they were beneficial, but I also find they&#x27;re rarely worth the bother.”<p>Also sums up my feeling of reading this author.<p>I only read the first two paragraphs and determined this article needs unit and integration tests.<p>Assert sentences:<p><pre><code> Have noun, verb, and subject Are not run-ons Do not contain typos that render them unintelligible</code></pre>
Kiroalmost 5 years ago
I only write broad blackbox tests that make the same actions as users and look at the end result (e.g. has the DB been updated accordingly).
pelasacoalmost 5 years ago
while agreeing with almost all points here (hackernews never let me down), I would like to point out that tests give specially newcomers the confidence to start to contribute as soon as the development environment is up and running. So yes tests not only helps us avoiding regressions, but it ramps up dramatically the on-boarding of new developers.
zabilalmost 5 years ago
From my experience, easily testable code (this means applications and interfaces) is stabler and easier to maintain.<p>By testable code I mean code that&#x27;s either easy to test or write tests for. I see a lot of tests retrofitted assuming that the code must not change. So my thumb rule is if it&#x27;s hard to test then re-design it.
madmaniakalmost 5 years ago
Any successful project I participated (tons) sacrificed tests writing, still used health checks. Any BS project I participated (+&#x2F;- the same amount) was full of linters, TDD, and lots of testing bureaucracy and disoriented people which were thinking all is good because there&#x27;s 100% test coverage.
camgunzalmost 5 years ago
The amount of test code in your app is (well, should be anyway) directly proportional to the risks inherent in your process plus the lack of verification tooling in your platform (type system, preconditions, etc). When you consider them this way, they’re basically a code smell.
Okkefalmost 5 years ago
It doesn&#x27;t need to be perfect to be perfectly useful.<p>Not testing because it can&#x27;t be perfect is a fallacy.
评论 #23756018 未加载
Ace17almost 5 years ago
&gt; &quot;Certainly, one approach is to just write good tests that don&#x27;t have these problems. If you like writing tests and are very good at it, you may continue to do so. &quot;<p>The article should be renamed to &quot;Against Bad Testing&quot;.<p>Good tests <i>do</i> exist ... but they are <i>hard</i> to write (but easy to maintain). They require a lot more software design competence that writing non-testable production-code-that-works-today-and-maybe-tomorrow. An example of good tests: have a look at the Ninja codebase.<p>Writing such good tests for a legacy codebase (not written with testability in mind) is even harder (and I&#x27;m not sure that it&#x27;s always possible in this case. It might. But I don&#x27;t have any example).<p>Forcing everyone to write tests when they don&#x27;t have the competence yet is a recipe for disaster and false conclusions (&quot;this testing thing doesn&#x27;t work &#x2F; is harmful&quot;).<p>PS: now that I think of it, do we have a list of well-tested public-source codebases? this could be a good pedagogical tool.
jyriandalmost 5 years ago
For me testing is a way to run small snippets of code without the need to spin up the whole application. I write lot of unit tests(almost TDD) when working with java, but when working with clojure or python I mainly use the REPL to drive the code.
gfioravalmost 5 years ago
I honestly don&#x27;t get the fret. I must be one of the few people in the industry that actually TDD. I write the test first as a sort of &quot;design research&quot; phase. This industry pays, is it that hard to expect discipline?
squirrelalmost 5 years ago
The standard book on avoiding the test anti-patterns described here is <a href="http:&#x2F;&#x2F;www.growing-object-oriented-software.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.growing-object-oriented-software.com&#x2F;</a> .
mD5pPxMcS6fVWKEalmost 5 years ago
Testing arose with the advent of PHP and JavaScript. Because compilers check nothing in these languages, testing must be written separately, otherwise it&#x27;s impossible to make even a short program without errors.
maxbondalmost 5 years ago
For the past few months I&#x27;ve been writing property tests with Hypothesis for Python (<a href="https:&#x2F;&#x2F;hypothesis.readthedocs.io&#x2F;en&#x2F;latest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hypothesis.readthedocs.io&#x2F;en&#x2F;latest&#x2F;</a>) and Proptest for Rust (<a href="https:&#x2F;&#x2F;altsysrq.github.io&#x2F;proptest-book&#x2F;intro.html" rel="nofollow">https:&#x2F;&#x2F;altsysrq.github.io&#x2F;proptest-book&#x2F;intro.html</a>). The tl;dr on property testing is that, rather than testing just one manually solved case, you describe an invariant (the example given of x + y &lt; limit being a good one) and a method of generating random inputs, and the test runner will use that information to fuzz your code.<p>I&#x27;ve found that I get better tests, and that I can write tests faster. It&#x27;s also an antidote to Unangst&#x27;s point that the developer who failed to imagine an test case while programming won&#x27;t necessarily have an epiphany when they go to write tests.<p>But it isn&#x27;t always a good fit with one&#x27;s domain.
jrmgalmost 5 years ago
Can someone give some examples of well-unit-tested open source projects?<p>It seems like this should be googleable, but all I get when I try to find this is unit test frameworks and blog posts about how to unit test.
评论 #23756119 未加载
评论 #23788284 未加载
评论 #23756055 未加载
ulisesrmzrochealmost 5 years ago
Never finish your essays all wishy washy like that. You don’t like shitty tests. Not a very controversial or enlightening end there.<p>If you’re gonna be against testing, then be against it
jherdmanalmost 5 years ago
I didn&#x27;t even make it past the first sentence. What a lame opinion! Tests are provably great, especially if you want contributors to your project, or give even half a hoot about documenting behaviour. I could care less if you don&#x27;t like writing them. Just do it.
ravenstinealmost 5 years ago
I just dislike tests that don&#x27;t test what&#x27;s actually important.<p>For instance, if you are writing an application, then you probably don&#x27;t need to be writing unit tests for internal APIs, since they might as well be considered private entities. Just write tests for application behavior. This stance seems rare, in my experience. Every team I&#x27;ve worked with insists on testing effectively private logic as well as testing the application at a high level, which takes a lot of time.<p>A lot of debugging time can be saved by guarding against unusual circumstances and providing useful error messages. Unfortunately, most people treat tests as if they <i>are</i> the documentation for how parts of the application are supposed to behave, which I think is generally the wrong way to look at it since tests can be difficult to decipher when you dive back in to them.<p>The greatest sin of testing, in my opinion, is the idea that if you write enough tests that you can avoid errors. The only way in which this works in some capacity is when you write your tests while you code(aka TDD). But the reality is that you simply can&#x27;t avoid bugs no matter how meticulous you are in writing your tests. Every application I&#x27;ve worked on has ass loads of tests, and yet there are regressions every week. This is not the fault of anyone in particular, but the nature of the beast. In which case, you&#x27;ve got to decide whether it&#x27;s worth testing all the minutiae of your application, or spend more time on the stuff that you really care about. Every test you add contributes to wasted developer time, especially when it gets to the point that it&#x27;s no longer practical for programmers to run your entire test suite locally.<p>EDIT: To expand upon this, while I think integration tests are <i>better</i> than unit tests, generally speaking, I don&#x27;t think they a good substitute for high level <i>application</i> tests when writing an application(not an API, framework, or library).<p>Your best bet for testing the truly desired behavior, getting an understanding of how performant your application is, and measuring your app&#x27;s complexity, is application tests. If your application test requires a ton of ridiculous special cases to be set up, or faking test data becomes difficult, that&#x27;s a sign that your app is too complicated and that you should stop and address that before anything else. If your application tests are becoming slow, that means that the application will become slower for your <i>users</i>. Integration and unit tests are unlikely to capture how your app is <i>actually</i> going to behave or perform. If you TDD your application while writing application tests, you will quickly know whether your work is improving the app or making it worse.<p>Appliction tests, by design, are much slower than low-level tests. This is a <i>good</i> thing, because you&#x27;d better make good choices or else your test are going to take forever to run. Things like unit tests sweep performance problems under the rug.<p>The problem with good application tests is that adding them to an existing app that performs poorly takes a tremendous amount of effort. If your app is well established, has tons of lower-level tests, but runs like crap and has a bunch of over-complicated inner workings, then getting new application tests in there will be painful and might not even be worth the effort to the business. Sadly, so many apps I&#x27;ve worked on faced a great deal of rot, which I think is largely a result of flawed testing philosophy, that made it very difficult to improve.
评论 #23762959 未加载
mdomsalmost 5 years ago
I sincerely hope that the author of this article is not employed in a professional software capacity, or at least not in any software I rely on. As someone who was raised in the peak of the Kent Beck test-first philosophy, reading something like this is shocking to me.<p>Based on the declining quality of everyday software it&#x27;s not altogether surprising, but it&#x27;s disturbing to see it written in black and white so brazenly.
评论 #23756126 未加载
评论 #23758826 未加载