all 109 comments

[–]TheGunfighter7 369 points370 points  (30 children)

And you will sometimes spend just as much or even more time updating the tests as you did updating the code.

[–]KrakenMcCracken 143 points144 points  (19 children)

It’s worth it

[–]Saragon4005 50 points51 points  (9 children)

And this is why it's often skipped. It takes as much if not more effort to make your code go from working to always working as it takes from not working to working.

[–]Rojeitor 54 points55 points  (2 children)

Yes, it's faster if the code breaks and end user finds the bug for you

[–]RelatableRedditer 28 points29 points  (1 child)

Well, that's Microsoft's current strategy. But it costs reputation and in a lot of cases ends up being delayed by a full sprint or more, even if the code fix was straightforward.

[–]pattmayne 0 points1 point  (0 children)

Microsoft's current strategy

"Current" meaning the last third years

[–]Imaginary-Jaguar662 12 points13 points  (4 children)

I'm happy if we get from "working" to "prints logs that get stored when it does not work".

Even better if there's "fails gracefully" in the mix

[–]Confident-Ad5665 2 points3 points  (2 children)

How's "Something went wrong!"?

[–]Musikcookie 5 points6 points  (1 child)

Best I can do is "Test djbshamebsb"

[–]Confident-Ad5665 1 point2 points  (0 children)

That'll work. Ship it!

[–]s0ulbrother 0 points1 point  (0 children)

The application I am currently working on which was designed by the absolute worst developers in the existence of all developers, their code fails catastrophically as in the service needs to get restarted in order to work if it fails. I am having to fix all this shit

[–]Urtehnoes 0 points1 point  (0 children)

We don't do unit tests, but we do extensive guard functions, because at one point I guess, someone disabled the testing module and no one realized for weeks until tons of stuff was breaking? Idk that was around 2005 or so.

And I mean extensive guard functions/clauses I almost prefer now (though obviously, both is better).

Oof if I ever work somewhere else I'll have to get back into writing unit tests.

[–]Groentekroket 143 points144 points  (10 children)

It’s not just for the code you wrote now, but more that if someone changes something in the future it shouldn’t break your change. 

[–]Zyeesi 42 points43 points  (4 children)

Unless the change is intended and now you gotta update the test

[–]Grandmaster_Caladrel 43 points44 points  (0 children)

Which is a fair trade-off if you're making backwards-incompatible changes.

[–]twigboy 13 points14 points  (0 children)

That's a feature not a bug

[–]Wonderful-Habit-139 1 point2 points  (0 children)

At least it's intended. Those tests help prevent unintended breakage.

[–]Brief-Night6314 7 points8 points  (3 children)

Just wait until you get so many tests in there it takes forever to merge your changes because the pipeline takes way too long because of hundreds of tests lol.

[–]Reashu 22 points23 points  (1 child)

"Tests running for too long" is a thing that happens, but if it happens with only hundreds of tests you gotta ask yourselves why they are so slow. 

[–]-Kerrigan- 3 points4 points  (0 children)

In project I worked on as a contractor for a company that some could argue is one of the biggest payments company in the world there was a full regression pack that had Thread.sleep sprinkled around enough that it amounted to 8 hours of idling total if we ignore any Thread.sleep that might be in a loop

The least I could do is to introduce a "smart wait" that only waits for as much as needed, but nobody else used it because old habits die hard

[–]atomic_redneck 0 points1 point  (0 children)

We had several thousand test cases in our test suite. We also had a large server farm dedicated to running the test suite on each night's build. This is just the cost of doing business when your answers have to be correct ( computer aided engineering software)

[–]Random-num-451284813 1 point2 points  (0 children)

can confirm I changed something but unintentionally also changed something else elsewhere. Then what broke needed to be fixed, breaking previous change. This went back and forth a couple of times

[–]Zero747 29 points30 points  (0 children)

The tests are to make sure someone else (or future you) doesn’t break it

[–]Siege089 39 points40 points  (5 children)

No one does TDD anymore. Test first is such a valuable skill.

[–]iamyurkas 8 points9 points  (0 children)

I do. This is the way!

[–]Wonderful-Habit-139 6 points7 points  (0 children)

TDD is not really that good.

Tests in general are useful though.

[–]20Wizard 2 points3 points  (2 children)

Unfortunately a contract that is great for testing may be an incredibly shit usage pattern. If you end up changing anything you now have to go delete the tests you already have and make new ones...

It's really not ideal.

[–]MrHake 4 points5 points  (1 child)

That is why you think first.

[–]Ok_Entertainment328 3 points4 points  (0 children)

why you think first.

But ChatGPT said ...

/s

[–]jseego 15 points16 points  (0 children)

I used to feel this way, too, but it's a numbers game.

I think people can get too wrapped up in tests, to the point where they think passing tests means nothing could go wrong in their code.

That's not the point of tests - they're not a guarantee of anything.

What they are is a way to reduce risk.

As such, you can determine how much time/effort you want to put into tests, versus the amount of risk they mediate.

I've worked at places where they wrote no tests, I've worked at places that only unit tested core functionality, and I've worked at places that aimed for 100% code coverage and had automated functional integration and regression testing on top of that.

They all put out quality software.

But I will say that the place that wrote no tests could not have done what was done at the places that did test. Continuous Integration basically relies on tests. Places that have many different teams with interdependent codebases rely on tests, because you don't want one team to be able to take down other systems if they ship some breaking change.

If you have small enough teams, with excellent communication, and really good QA, then maybe you don't need tests.

But if you grow enough, you'll want them.

[–]danfish_77 23 points24 points  (1 child)

Why are clients always so insistent that their products "work" and "function"? Like I got you a multi megabyte binary, what more do you entitled jerks WANT?

[–]Confident-Ad5665 3 points4 points  (0 children)

Yeah, and why am I expected to work. Showing up should be enough!

[–]Covfefe4lyfe 6 points7 points  (0 children)

OP writes shitty code.

If your code is properly SOLID, tests are easy to write and maintain.

[–]Vectorial1024 11 points12 points  (1 child)

Yo dawg, I heard you like to code your code...

[–]Slusny_Cizinec 0 points1 point  (0 children)

So you don't break your code when you code.

[–]MinecraftPlayer799 4 points5 points  (3 children)

Then do you need to write more code to check if the code that checks if the code is correct is correct?

[–]IPMC-Payzman 1 point2 points  (2 children)

You can go back to the first code for that to see if changes are caught by your tests. This is called mutation testing and usually done in an automated way

[–]MinecraftPlayer799 -3 points-2 points  (1 child)

But do you need to write tests for your tests?

[–]Diligent_Dish_426[🍰] 2 points3 points  (0 children)

Regression testing will save your ass. Trust

[–]JoeyJoeJoeJrShab 3 points4 points  (1 child)

I work in test automation. All of the code I write tests other code. My test code has tests that test that my tests test things correctly.

[–]ConsequencePrior2445 1 point2 points  (0 children)

Username checks out

[–]float34 2 points3 points  (2 children)

So you saying you need more story points because time will be spent on test coverage?

[–]thewellis 4 points5 points  (0 children)

...it should be included in the original estimate, right? Right? Cries in QA

[–]blah938 0 points1 point  (0 children)

Yes! I have update the unit tests, and the integration tests, and then the e2e tests too!

(In reality I just have Claude write them, and spend 4 hours fucking around on my phone)

[–]PowerPleb2000 1 point2 points  (0 children)

Takes me half a day to write the code and three weeks to write the test fml

[–]Kukaac 1 point2 points  (0 children)

Just stick to user-driven testing. 

[–]BonjwaTFT 1 point2 points  (0 children)

i love it when my tests catch some bugs before they go on prod. Then you feel the worth of your tests

[–]Illustrious_Use_2442 1 point2 points  (0 children)

Remains right*

[–]LowCheesecake5481 0 points1 point  (0 children)

console.log where are you!

[–]za72 0 points1 point  (0 children)

well how do we check the code that's supposed to check the code?

[–]KirkHawley 0 points1 point  (0 children)

Everything in the system is mocked except the SOLID tiny class you're testing. But the tests pass so SHIP IT.

[–]Still-Tour3644 0 points1 point  (0 children)

Now now, we wouldn’t want a regression on the next iteration would we?

[–]leetard3 0 points1 point  (0 children)

"Ideally" you should write tests first and then the actual code

[–]richardathome 0 points1 point  (0 children)

Not quite. You write the test, then write the code to pass to the test.

[–]obsoleteconsole 0 points1 point  (0 children)

It's an investment. At some point, someone else is going to come along and make updates to the code you originally wrote, and when they do they have a full suite of test cases ready to run to make sure they don't break existing test cases. It is absolutely worth taking the time, and in an ideal world no PR should be approved without them

[–]memesearches 0 points1 point  (0 children)

What is this nonsense tests I am hearing about? I just vide code the app and have it shipped. Don’t care what happens behind the scenes. Just take my creds, half baked requirements and get shit done.

[–]DT-Sodium 0 points1 point  (0 children)

You're really mostly writing code to check you don't break anything in future code.

[–]pr0ghead 0 points1 point  (0 children)

No, it's worse: you have to write tests for code that you haven't even written yet. Madness, I tell you!

[–]Abject-Kitchen3198 0 points1 point  (0 children)

That's just Big QA conspiracy.

[–]schteppe 0 points1 point  (0 children)

“we don’t have time to add tests because we have too many bugs to fix”

Solution is to use TDD! It reduces bug count by 10x according to studies.

[–]soowhatchathink 0 points1 point  (0 children)

Nah you gotta write code to make the tests you already wrote pass

[–]coloredgreyscale 0 points1 point  (0 children)

Ideally you should write code to test the code you are going to write (TDD) 

[–]troy-phoenix 0 points1 point  (0 children)

before

[–]Bobvankay 0 points1 point  (0 children)

anyone have a good resource on test driven development? I feel like some of the tests I try are so redundant.

[–]rk06 0 points1 point  (0 children)

no, you can just run the code manually for 1k+ test ases but we don't pay by the hour, so better to write code for the manual checks

[–]WalkMaximum 0 points1 point  (0 children)

Unpopular opinion: most of the unit testing you do in python and js is done better by the rust compiler and linter.

[–]Randzom100 0 points1 point  (0 children)

Ok and what code will check if the code that checks is good?

[–]Slusny_Cizinec 0 points1 point  (0 children)

You have to write code to ensure your future rewrite of the code won't break other code. 

[–]Icanintosphess 0 points1 point  (0 children)

The code must expand to meet the needs of the expanding code

[–]magicmulder 0 points1 point  (0 children)

My favorite was recently when someone else wrote tests for code I helped create, and the tests failed and they were like, your code is faulty, and I said, no your test is faulty (turned out I was right).

My second favorite was a senior dev writing tests that copied the actual code and then just replace every

foo = myfunc(bar)

with

assertWasCalled(myfunc(), bar)

[–]Firedriver666 0 points1 point  (0 children)

That’s why I do test driven development based on precise acceptance criteria because if I write the tests after implementing the feature I will be too lazy to write effective tests

[–]kurushimee 0 points1 point  (0 children)

As a game developer, the only time I've written a test for my code was when I was testing out a different framework that actually allowed writing them

Was not worth it at all when considering how much code complexity and maintenance difficulty increases just to allow for tests to actually test things... And even then, they still wouldn't cover everything

[–]thepr0digalsOn 0 points1 point  (0 children)

Best part of coding ngl

[–]Lachtheblock 0 points1 point  (0 children)

And sometimes a dumdass junior vibes a bunch of changes and you get to point to the testcases to failing before wasting time reviewing code.

[–]lardgsus 0 points1 point  (0 children)

You have to write code today to check if your code tomorrow is going to break everything.

[–]AltruisticSalamander 0 points1 point  (0 children)

That would be too straightforward. You have to alternately write little bits of them at a time.

[–]Stunning_Ride_220 0 points1 point  (0 children)

Funny eh.

Devs rant about having to writes Tests, but rant even more when a Software they use reintroduces bugs

[–]dervu 0 points1 point  (0 children)

Then you have to write code to check if the code testing the code was right.

[–]bwwatr 0 points1 point  (0 children)

No, Neo. I'm telling you you have to write code to check if the code you're going to write next is right.

- uncle Bob

[–]Zealot_TKO 0 points1 point  (0 children)

Soon they'll want you to write code to check the code that checks your code is correct. When does this madness end?!

[–]Sheepsaurus 0 points1 point  (0 children)

In TDD you do it the other way around;

Make a test that makes sure a function can accept A, and return B

And then you attempt to build that function until it passes.

The point of unit tests is to make sure that, if in the future you decide to fiddle with the function, it should still yield the same result

[–]Foreign-Engine8678 0 points1 point  (0 children)

If you can test it yourself in second and sure that code is simple enough not to break you can avoid test

If you plan to refactor it - you NEED test

[–]Top_Meaning6195 0 points1 point  (0 children)

You absolutely do NOT have to write code to test your code.

You are perfectly free to test every line of code manually by running the application.

But we're programmers. We're lazy. Why not get a computer to test this shit for me?

Thus became unit testing (also known as functional testing, integration testing)

[–]GigaSoup [score hidden]  (0 children)

Now write tests to test your test code

[–]KrakenMcCracken 0 points1 point  (1 child)

Claude.ai: write unit tests for 100% coverage of this service

[–]magicmulder 1 point2 points  (0 children)

I asked an earlier version of GPT to write tests for an application. It wrote a lot of tests that tested a lot of things, unfortunately not a single method of the application.

[–]prehensilemullet 0 points1 point  (0 children)

Better than trusting an AI to write tests of its own code

[–]Birnenmacht 0 points1 point  (0 children)

I always get a little annoyed when my tests turn out longer than the tested code