News for hackers. Stuff that matters.
Re:Ask HN: What made you change your mind about a programmin... by DanHulton on Sunday March 03, 2019 @05:36PM (#19297381)
Testing.

Unit testing to me seemed akin to drinking 8 glasses of water every day. A lot of people talk about how important it is for your health, but it really tends to get in the way, and it doesn't seem to really be necessary. Too frequently, code would change and mocks would need to change with it, removing a good chunk of the benefit of having the code under test.

Then I started writing integration testing while working on converting a bunch of code recently, and it has been eye-opening. Instead of testing individual models and functions, I was testing the API response and DB changes, and who really cares what the code in the middle does and how it interfaces with other internal code? So long as the API and DB are in the expected state, you can go muck about with the guts of your code all you want, while having the assurance that callers of your code are getting exactly out of it what you promise.

Unit test suites would break all the time for silly reasons, like someone optimizing a function would mean a spy wouldn't get called with the same intermediary data, and you'd have to stop and go fix the test code that was now broken, even though the actual code worked as intended.

Integration tests (mainly) only break when the code itself is broken and incorrect results are getting spit out. This has prevented all kinds of issues from actually reaching customers during the conversion process, and isn't nearly so brittle as our unit tests were.

Re:Ask HN: What made you change your mind about a programmin... by jondubois on Sunday March 03, 2019 @06:17PM (#19297554)
I have the same experience. Integration tests are the best. They test only what really matters and allow you to keep flexibility over implementation details.

When your TDD approach revolves around integration tests, you have complete freedom to add, remove and shift around internal components. Having the flexibility to keep moving around the guts of a system to bring it closer to its intended behavior is what software engineering is all about.

This is also how evolution works; the guts and organs of every living creature were never independently tested by nature.

Nature only cares about very high-level functionality; can this specimen survive long enough to reproduce? Yes. Ok, then it works! It doesn't matter that this creature has ended up with intestines which are 1.5 meters long; that's an implementation detail. The specimen is good because it works within all imposed external/environmental constraints.

That's why there are so many different species in the world; when a system has well defined external requirements, it's possible to find many solutions (of varying complexity) which can perfectly meet those requirements.

Re:Ask HN: What made you change your mind about a programmin... by shittydeveloper on Tuesday March 05, 2019 @02:35PM (#19313480)
I'll would like to watch you running around and trying out everything when integration tests fails and you don't know which part of the code base caused the failure, while I just run all the specs and figure out the exact unit of code that is causing the problem.
Re:Ask HN: What made you change your mind about a programmin... by jondubois on Tuesday March 05, 2019 @02:59PM (#19313682)
That would not happen because each of my integration test cases are properly isolated form each other. If any specific test case starts failing, I just disable all other test cases and start debugging the affected code path; it usually only takes me a few minutes to identify even the most complex problems. Also, because I use a TDD approach, I usually have a pretty good idea about what changes I might have made to the code which could have introduced the issue.

Unit tests on the other hand are useless at identifying complex issues like race conditions; they're only good at detecting issues that are already obvious to a skilled developer.

* I restart the system from scratch between each test case but if that's too time-consuming (I.e. more than a few milliseconds), I just clear the entire system state between each test case. If the system is truly massive and clearing the mock state between each test case takes too long, then I break it up into smaller microservices; each with their own integration tests.

Re:Ask HN: What made you change your mind about a programmin... by shittydeveloper on Monday March 11, 2019 @08:11AM (#19358309)
Apologies sir...! When I said unit tests, I mean a specific unit of code (in TDD manner).

I mistunderstood your Integration tests. I understand them as something like checking from the end user contract. If so, without TDD, it won't be possible to track down the bug easily as with TDD.

Re:Ask HN: What made you change your mind about a programmin... by overkalix on Monday March 04, 2019 @06:15PM (#19306634)
Fyi, I'm definitely stealing your analogy.
Re:Ask HN: What made you change your mind about a programmin... by chasingthewind on Sunday March 03, 2019 @06:55PM (#19297740)
I will probably be the lone voice here defending mock testing but probably not for the reasons you'd expect. Does mock testing end up being brittle? Yes. Do you have to refactor the tests immediately after making small changes? Yes. Is there a cost to this? Yes.

Mock based testing however is the only thing I've ever encountered that forces me to think very, very clearly about what my code is doing. It makes me inspect the code and think about what dependencies are being called, how they're being called, and why they're being called.

I have found that this process is extremely valuable for creating code that is more elegant and more correct. I value mock tests not for the tests that I end up with at the end, but for the better production code that I wrote because of them.

Re:Ask HN: What made you change your mind about a programmin... by mdgrech23 on Sunday March 03, 2019 @10:27PM (#19298555)
What's stopping you from thinking clearly about the code while/after you write it? As I'm writing this sentence I'm thinking clearly about it and I'll probably reread it after I hit save. There's no reason you can't do the same w/ code.
Re:Ask HN: What made you change your mind about a programmin... by nirse on Monday March 04, 2019 @05:02AM (#19300075)
It's not that it can't be done, it's just that sometimes it is nice to have a tool that helps you think about the code. Unit tested code isn't better in any way, it's just a style of writing code that can produce good quality code, but not the only coding style that can do that. But I'd like to add that there have been quite a few refactors that I have done that would have been way harder if it hadn't been for the unit tests. It might not work for everyone, but I'd recommend you give it a serious try, it might be useful.
Re:Ask HN: What made you change your mind about a programmin... by AnimalMuppet on Monday March 04, 2019 @12:18PM (#19302931)
The tests don't just help you think about the code, they force you to do so. For those who are tempted to think "I can just do this quick change this one time; nothing will go wrong", tests force you to actually think.

Or they don't. If the tests just continue to work, then you ask yourself whether the change should have broken them. If not, you go on your way with a fair amount of confidence. But if the change should have broken the tests, then you have to look at why it didn't...

Re:Ask HN: What made you change your mind about a programmin... by mikekchar on Monday March 04, 2019 @01:50AM (#19299306)
Outside in development with mocks is awesome. Just replace the mocks when you know what you are building ;-)
Re:Ask HN: What made you change your mind about a programmin... by Bahamut on Sunday March 03, 2019 @10:05PM (#19298480)
My experience has been very much the opposite - integration tests are often very brittle, and finding the root cause is often almost a fools errand since stack traces are often no good for figuring out what went wrong, at least for web UI.

While yes, unit tests do have a maintenance burden, they are often reproducible, less flaky, give you targeted debug information, and run extremely fast.

There are heavy costs to integration and e2e testing that often gets dismissed by developers who often have not experienced the fast feedback loop a good fat unit suite gives you.

Re:Ask HN: What made you change your mind about a programmin... by yashap on Monday March 04, 2019 @01:29AM (#19299230)
Although I agree with you in general, integration tests that are really focused on the contract between two services can be pretty easy to debug, ESPECIALLY if you use request ids that are passed between services, and included in every log. It’s often a matter of simply searching for the request id in your logs and quickly seeing what happened.

E2E UI tests are definitely hard to debug though, in most cases. They still have value, but I’m a fan of the “testing pyramid” here. A small number of E2E UI tests, a decently large number of integration tests that each try to test a single contract between 2 services, and a tonne of unit tests to cover sad paths, detailed behaviour, etc.

Re:Ask HN: What made you change your mind about a programmin... by Bahamut on Monday March 04, 2019 @08:07AM (#19300901)
Totally agreed - the problem is when integration tests are used in lieu of what unit tests are for, which has been an increasing trend in the frontend web world I’ve seen, in large part because of UI frameworks not providing the tools to do testing well.
Re:Ask HN: What made you change your mind about a programmin... by yashap on Monday March 04, 2019 @10:36AM (#19302026)
Definitely. E2E UI tests are almost always brittle, flakey and hard to debug, you want a very small number of them just to test really core workflows. Drives me crazy too when I see frontend devs using them like UI unit tests, while writing no actual unit tests.
Re:Ask HN: What made you change your mind about a programmin... by danmaz74 on Tuesday March 05, 2019 @06:18AM (#19309779)
Ideally, you should have both unit and integration tests. See "Test Pyramid".
Re:Ask HN: What made you change your mind about a programmin... by danmaz74 on Sunday March 03, 2019 @06:55PM (#19297735)
I almost only use mocks for external calls (usually external APIs). Very rarely, I use them for some internal code that is unusually time consuming or difficult to set up.

A few months ago, I did a contracting job and the team I worked with used the "mock everything" approach, without even one integration test, which to me seemed crazy (especially for a component which was calle "integration layer").

I tried hard to find the advantages in this approach, studying what the rationale and the best practices were, and questioned my previous assumptions. In the end, I had to confirm those assumptions: even if there were hundreds of tests and they all passed, many logical errors weren't caught.

Even worse, they gave a false sense of confidence to the team, and made refactoring super-slow. But the team leader was super-convinced it was the best idea since sliced bread.

Re:Ask HN: What made you change your mind about a programmin... by taurath on Monday March 04, 2019 @12:58AM (#19299121)
People I’ve worked with have had that idea, and I’ve found they’re most frequently from the games industry or from contract shops. In both of those, the maintenance of the code over time is far less important than that it works on the ship date.

Additionally, people with large state machines with too-complex sets of possible states (games, big frontends without a top level state management system) tend to only unit test because it’s frequently too much of a pain to set up an integration runtime environment. Places with lots and lots of manual QA testers.

Re:Ask HN: What made you change your mind about a programmin... by danmaz74 on Monday March 04, 2019 @06:48AM (#19300534)
Yes, it's for sure a quicker way to have 100% test coverage...
Re:Ask HN: What made you change your mind about a programmin... by u801e on Sunday March 03, 2019 @06:18PM (#19297564)
> Too frequently, code would change and mocks would need to change with it, removing a good chunk of the benefit of having the code under test.

A lot of people overuse mocks when testing. In fact, using mocks enforces coupling between different methods because a lot of people use them to assert that a method with a specific name was called with specific parameters or they create one that asserts a method with a certain name returns a certain value. So when one wants to refactor, they not only have change the code; they need to update all the mocks that reference it as well.

I've found that a better way to structure code is to take the result of an external dependency and pass it in as a parameter to a method that will process it. Then when I unit test that method, I just pass in what I expect from that dependency and assert on the return value of that method. I don't try to unit test the outer method that calls the dependency by creating a mock call for it.

> Then I started writing integration testing while working on converting a bunch of code recently, and it has been eye-opening. Instead of testing individual models and functions, I was testing the API response and DB changes, and who really cares what the code in the middle does and how it interfaces with other internal code?

It makes it easier to isolate the cause of the error rather than having to search to the entire call chain to find it (especially if it's a logic error that doesn't result in an exception). Plus, integration test suites take a lot longer to run and can have timing issues due to caching or other reasons which can result in sporadic failures.

Re:Ask HN: What made you change your mind about a programmin... by virtualmic on Sunday March 03, 2019 @11:54PM (#19298880)
Both unit and integration tests have their place. This talk was excellent in explaining it to me (with functional cores, imperative shells). Unit test functional cores, use integration tests for imperative shells: https://www.destroyallsoftware.com/talks/boundaries

I am fan of Gary Bernhardt ever since viewing this talk.

Re:Ask HN: What made you change your mind about a programmin... by alexval on Sunday March 03, 2019 @06:54PM (#19297731)
My first job I wrote c++ for a win32 desktop app. I hated unit testing. My workflow was write the code, compile it, trigger the scenario, step through the code, write some unit tests after I knew it worked. It was the expectation on my team to write UTs so I did it. Fast forward to a different team I learned from a co-worker how UTs can help you influence your design. If you find yourself doing a ton of frustrating work to set up your UT scenarios there's probably a way of fixing the design to be less coupled that would allow you to test the code better. Now I think of UTs more as a way to help me understand how the design of my code is working and I get some extra validation out of it as well.
Re:Ask HN: What made you change your mind about a programmin... by pjmlp on Monday March 04, 2019 @02:18AM (#19299412)
My trick question to TDD advocates is how to develop native apps following those principles, after all no GUI change is allowed without a test.
Re:Ask HN: What made you change your mind about a programmin... by magduf on Monday March 04, 2019 @02:20PM (#19304351)
GUIs don't lend themselves to unit testing at all, because the requirements aren't mathematical, but are instead based on human factors.

For GUIs, the proper approach is to unit-test the functionality underneath, not the GUI itself.

Re:Ask HN: What made you change your mind about a programmin... by pjmlp on Monday March 04, 2019 @02:22PM (#19304369)
Which leads to convoluted architectures just to be able to follow "only write code which there is a failing test for".
Re:Ask HN: What made you change your mind about a programmin... by romwell on Monday March 04, 2019 @08:26PM (#19307364)
How are these convoluted?

After all, any program out there does something. If you know what it's doing, you know what it should do, and what it shouldn't. That means you can test it.

Re:Ask HN: What made you change your mind about a programmin... by pjmlp on Tuesday March 05, 2019 @12:51AM (#19308395)
Because given how GUI frameworks are implemented, one needs to add explicit workarounds to follow "only write code for which there is a failing test".

After all, writing the test needs to be possible, to start with.

So adapters, views, commands and what have you need to exist only to fulfill such purpose, and even then, their interactions with the GUI layer don't get tested.

So one is creating them, without knowing if they are the right elements for the GUI layout.

Hence why testing, 100% behind it, TDD not so much.

Re:Ask HN: What made you change your mind about a programmin... by AnimalMuppet on Monday March 04, 2019 @12:23PM (#19302997)
In my book, the UI isn't part of unit testing - at least, the views aren't. The models and controllers (to use the MVC paradigm) might be, though.
Re:Ask HN: What made you change your mind about a programmin... by wakamoleguy on Sunday March 03, 2019 @06:15PM (#19297542)
The integration tests that you are describing behave much like I would expect unit tests to behave. Give an input, assert the results (return value or state change). The example of optimizations breaking the unit test could be either a poor test (If the function doesn't need to call that intermediate with that data, why is it being tested?). Oftentimes the spy is added to the test because there is unnecessary tight coupling between two units.

This isn't to say that integration tests aren't great, too. They all tell different stories. I like unit tests, as they force me to think about modules as units. If a unit is hard to test or brittle, it may need more attention to its design.

Re:Ask HN: What made you change your mind about a programmin... by stevesmithwick on Monday March 04, 2019 @05:00AM (#19300068)
A good use of mocks/spies is if you need to test a side-effect. For instance: did your code call that service with the right parameters?
Re:Ask HN: What made you change your mind about a programmin... by jMyles on Monday March 04, 2019 @03:24AM (#19299650)
I had this experience as well, but then I began to realize that, as the codebase got bigger (let's say, for your metaphor, I was exercising more) that I really actually did want unit tests (that I needed more water).

As the codebase gets larger and more complex (and interesting!), I want unit tests to fail because of small changes. That's actually useful feedback, whereas the simple, brutal failure of an integration test is just not granular enough to quickly help me understand the details of the change.

Re:Ask HN: What made you change your mind about a programmin... by jwdunne on Monday March 04, 2019 @04:36AM (#19299961)
This has been my experience too. On a project I'm working on now, I went majority integration tests. I have about 200 of them and they now take 2 minutes per run. VirtualBox and Jest doesn't help. To stay sane, I've had to run only relevant tests. They're great for a final sweep but they do slow down the feedback loop quite a lot.

For future tests and projects, unit tests do have a place and I'll make better use of them.

A good learning experience, none the less.

Re:Ask HN: What made you change your mind about a programmin... by jorblumesea on Sunday March 03, 2019 @11:33PM (#19298800)
I would disagree. Unit tests make sure your code is clean and composable. It's hard to write unit tests if you have hundred line methods etc. It usually forces you to write smaller chunks of code. Integration tests make sure it works in test/prod. You can have a complete spaghetti mess and still pass your integration tests. You can also have good unit test coverage but break prod.

They serve two different purposes.

Re:Ask HN: What made you change your mind about a programmin... by JesseAldridge on Sunday March 03, 2019 @06:17PM (#19297557)
I think most would agree that integration tests are better. The problem is they tend to be slower. Having to initialize the system appropriately for every test (e.g. writing to the database) tends to limit the number of tests you can have.

Unit tests scale a lot better. That's why most generally use a pyramid structure: lots of unit tests, a moderate amount integration tests, and a few end-to-end tests.

Re:Ask HN: What made you change your mind about a programmin... by cellularmitosis on Monday March 04, 2019 @12:02AM (#19298913)
An approach of “almost” integration tests can be much faster. I.e. rather than spinning up a full-blown web server or database, use fake objects for those. Uncle bob describes refactoring the architecture of a project to make integration tests faster by decoupling the web server.

Mentally, something like clojure’s ring framework make this easier to grasp: the abstraction it provides is dictionary-in, dictionary-out. Once you have something like this, there’s no need to spin up a web server to do integration testing: you just shove a bunch of dictionaries and and make sure the output dictionaries are what you expected.

A good approach is to use each technique where you get the most bang-for-buck: use unit tests only for pure functions, and decouple your system in a way that integration tests can be reduced to simple data-in data-out (which also makes them very fast)

Re:Ask HN: What made you change your mind about a programmin... by cellularmitosis on Monday March 04, 2019 @12:04AM (#19298923)
Ah I forgot the link https://youtu.be/WpkDN78P884
Re:Ask HN: What made you change your mind about a programmin... by humanrebar on Sunday March 03, 2019 @09:59PM (#19298460)
Unit tests also tend to have fewer dependencies and are therefore more portable and robust.

If your integration tests can be reasonably be set up with a couple containers, great, but not every system is that flexible. And not every data store is that simple to provision.

Re:Ask HN: What made you change your mind about a programmin... by MarkMc on Monday March 04, 2019 @01:22PM (#19303732)
With an in-memory database like Derby I find my test cases run fast enough
Re:Ask HN: What made you change your mind about a programmin... by h0l0cube on Sunday March 03, 2019 @11:05PM (#19298688)
Re:Ask HN: What made you change your mind about a programmin... by arduinomancer on Sunday March 03, 2019 @05:45PM (#19297417)
Just adding to this, for me I think the benefits of testing became really clear in situations where you end up fixing the same bug twice.

Knowing about that bug is really valuable knowledge and not adding a test for it is basically like throwing away that knowledge instead of sharing it for future people working on the project.

Re:Ask HN: What made you change your mind about a programmin... by yougotrioted on Sunday March 03, 2019 @10:27PM (#19298553)
I completely agree. If you have limited time to write tests, then I've found that integration tests provide the most value by far. If you're happy with your suite of integration tests, then it's also great to have a set of unit tests.
Re:Ask HN: What made you change your mind about a programmin... by buzzy_hacker on Sunday March 03, 2019 @06:11PM (#19297524)
> Unit test suites would break all the time for silly reasons, like someone optimizing a function would mean a spy wouldn't get called with the same intermediary data, and you'd have to stop and go fix the test code that was now broken, even though the actual code worked as intended.

Can you or others speak more about this? I was taught that verifying function calls for spies/mocks was good practice. But, I encountered this problem just the other day when I refactored some Java code for a personal project. Everything still worked perfectly, but, exactly as you said, the intermediate function calls changed so the tests would fail due to spies/mocks calling different "unexpected" functions.

I'm an intermediate programmer so can someone with more experience fill me in with what's best practice here and why? Do I update the test code to reflect the new intermediate function calls? But this whole approach now seems silly since a refactoring that doesn't affect the ultimate behavior of the function that is under test will break the test and that seems wrong. So do I instead not verify function calls when using spies/mocks? In that case, what is the use case for verifying spies/mocks?

Re:Ask HN: What made you change your mind about a programmin... by ht85 on Sunday March 03, 2019 @07:02PM (#19297776)
What you want to spy on are side-effects that are part of the function's contract.

If you have a function that fetches data, you shouldn't test that its hitting the data layer, only that the correct data is returned. This way when you improve the function to not hit the data layer at all under some conditions, your tests will keep passing.

On the other hand, if that function is supposed to log metrics or details about its execution, you should test that ,as it is part of its contract and can't be inferred from the return value.

Re:Ask HN: What made you change your mind about a programmin... by int_19h on Sunday March 03, 2019 @09:14PM (#19298293)
Your tests should be driven by your contracts. Is there a contract for the component being tested that says, "it calls function X if Y"? If yes, then test that. If not, then you shouldn't be testing such an implementation detail anymore so than you'd test values of local variables inside a function at some point in the middle.

The important part is to remember that not every function is a component, and not even every class by itself. Where to draw the boundary between components is itself an explicit design decision, and should be made consciously, not mechanically.

Re:Ask HN: What made you change your mind about a programmin... by danidiaz on Monday March 04, 2019 @02:08AM (#19299373)
This is usually called the classical vs. mockist, or test interactions vs. test final state debate.

Instead of mocks, some people prefer to build fakes / stubs which are versions of a dependency which are "fully operative" in a sense but with a simplified internal implementation. For example a repository that keeps entities in memory. (Not the same as an in-memory database! The fake repository wouldn't use SQL at all.)

Tests would check the final state of the fakes after the interactions, or simply verify that the values returned by the tested component are correct.

The hope is that fakes, while possibly more laborious to set up, allow an style of testing that focuses less on the exact interactions between components, and therefore is less brittle.

Some links:

- Mocks aren't stubs https://martinfowler.com/articles/mocksArentStubs.html#Class...

- From interaction-based to state-based testing http://blog.ploeh.dk/2019/02/18/from-interaction-based-to-st...

Re:Ask HN: What made you change your mind about a programmin... by jononor on Monday March 04, 2019 @09:29AM (#19301479)
What should be tested is that the function does what is promised to the caller. Which other function it uses to accomplish this task is a detail, which should generally not be part of this promise (encapsulation). So either the effects of the function must be returned by the function, or it is a side-effect, which must then be observable in some other way. Example: If a function is supposed to create new user, don't check that it calls some internal persistence or communication layer with some User info. Instead list the users in system before and after, check that the correct one was added. Try to make an action as this new user. This forces you to expose (a view of) internal state at the API surface, which makes the system more observable, usually very beneficial for debugging and fillings gaps in API.

Also, many of the assertions that are often put into unit-tests (especially at stub/mock boundaries) are better formulated as invariants, checked in the code itself. Design-by-contracts style pre/post-conditions is a sound and practical way of doing this. When this is done well, you get the localization part of low-level unit testing even when running high-level tests. Plus much better coverage, since these things are always checked (even in prod), not just in a couple of unit tests. And it is more natural when refactoring internal functions to update pre/post-conditions, since they are right there in the code. When a function disappears they also do.

I don't like the term "integration" tests though, as they hint at interactions between systems being the important thing to test. Integration between services / subsystems are just as much a detail as internal function calls. If using the real system during test is too complicated or slow, maybe it should be simplified or made faster? Only when that is not feasible do I build a mock.

Re:Ask HN: What made you change your mind about a programmin... by wakamoleguy on Sunday March 03, 2019 @06:20PM (#19297569)
If it is important to the operation of the function, from an outsider perspective, the intermediate call should be tested. Oftentimes this isn't the case, though. Most often, I see intermediate calls spied/mocked when they have side effects to be avoided. This is actually a sign of tight coupling between modules, and patterns like dependency injection can help make it easier to test.

The trick for me is focusing on what the unit does from a consumers perspective. Avoid testing implementation details (unless they are important side effects), and test the behavior that does not change. If you do that, then refactoring becomes easier, because tests will only break when the contract of the unit changes.

Re:Ask HN: What made you change your mind about a programmin... by jaabe on Monday March 04, 2019 @12:27AM (#19299006)
We buy software from a lot of different companies, sometimes we own the codebase but hire software companies to build, expand and maintain it, we also benchmark performance.

We have a lot of data that explicitly shows that automated unit-testing doesn’t work. One good example is one of our ESDH systems, which changed supplier in a bidding war, partly because we wanted higher code-quality.

It’s a two million line project, we paid for 5000 hours worth of refactoring and let the new supplier spend two years getting familiar with it and setting up their advanced testing platforms.

So far we’ve seen some nice performances increases thanks to the refactoring. It has more problems than it did before though, even though everything is tested by unit tests now and it wasn’t before.

We have a lot of stories like this by the way. I don’t think we have a single story where unit-testing actually made the product better, but we do have tested systems where we couldn’t say because they always had unit-testing.

Ironically we still do TDD ourselves on larger projects. Not because we can prove it works, but because everyone expects it.

Re:Ask HN: What made you change your mind about a programmin... by geezerjay on Wednesday March 06, 2019 @03:52AM (#19317376)
> We have a lot of data that explicitly shows that automated unit-testing doesn’t work.

At best you have data that shows that a poor unit testing implementation failed to deliver. A bad experience doesn't prove a whole tech strategy doesn't work when the whole world shows otherwise.

Re:Ask HN: What made you change your mind about a programmin... by a_imho on Monday March 04, 2019 @02:46AM (#19299517)
There was a comment on HN which I keep thinking about. What is the value of expensive testing when you are promptly alerted of critical problems and can deploy in under a minute? Obviously not applicable for every scenario, but at this point I think for most non critical systems a good rollback/plan B is at least as important as testing.
Re:Ask HN: What made you change your mind about a programmin... by geezerjay on Wednesday March 06, 2019 @04:09AM (#19317434)
> What is the value of expensive testing when you are promptly alerted of critical problems and can deploy in under a minute?

Because your users should not be your testers and you must catch bugs before deploying them in production.

You may be able to deploy in 3 minutes but it takes way more to debug and fix your bugs.

Testing helps the project to catch bugs prior to deploying them and also provides the infrastructure to avoid regressions.

Re:Ask HN: What made you change your mind about a programmin... by discreteevent on Sunday March 03, 2019 @06:00PM (#19297480)
You need to write a book and then get on the conference circuit with this message. You would be rowing against the tide but there is always hope!
Re:Ask HN: What made you change your mind about a programmin... by bradleyjg on Sunday March 03, 2019 @10:13PM (#19298503)
https://kentcdodds.com/blog/write-tests

Write tests. Not too many. Mostly integration.

Re:Ask HN: What made you change your mind about a programmin... by imhoguy on Monday March 04, 2019 @01:57PM (#19304116)
It is all about balance.

Use system/integration/functional/unit tests wisely.

For precise stateless stuff, like making sure your custom input format parser/regexp covers all edge cases, I prefer unit tests - no need to init/rollback database state.

Re:Ask HN: What made you change your mind about a programmin... by kayoone on Monday March 04, 2019 @01:40AM (#19299264)
you can also unit test in a more blackbox way where you test your interal APIs instead of the implementation. It makes sense to have both in many cases.
Re:Ask HN: What made you change your mind about a programmin... by entity345 on Monday March 04, 2019 @04:47AM (#19300023)
As is the case for all software, unit tests should be well designed.

If a unit test fails when the code under test hasn't functionally changed then it means that your unit tests are flaky.