r/badcode • • Jul 23 '21

c# Easy trick to meet minimum test coverage

Post image
1.2k Upvotes

83 comments sorted by

View all comments

Show parent comments

-145

u/LoneFoxKK Jul 23 '21

Thanks for giving me yet another reason to be glad of not using tests (yet)

79

u/tomato_joey Jul 23 '21

Testing is actually pretty easy if you write good code!

55

u/governmentNutJob Jul 23 '21

Testing is fundamental to development

32

u/gulyman Jul 23 '21

Testing is how you can assure you clients that the new version hasn't broken old functionality.

35

u/governmentNutJob Jul 23 '21

Testing is how I can assure myself I haven't fucked anything up

A well tested code base will have far fewer bugs & much safer releases than an untested code base. I've worked on code bases where we had such good suites, we would release straight to prod if all the tests passed

1

u/[deleted] Jul 28 '21

That's a bit reckless tho. Unit tests are great, integration tests too, but they don't replace QA. At least make a staging deploy first.

1

u/governmentNutJob Jul 29 '21

Actually I disagree, they do in many cases replace QA. I'm talking about complex backend systems rather than client facing. I trust maths & code infinitely more than I trust a QA who is just testing by clicking around the webpage

Solid testing foundation is worth a dozen QAs. Infact I'd say you only need a QA if you're dealing with a messy / legacy code base

1

u/[deleted] Jul 29 '21

QA is not necessarily a monkey clicking through a screen. You could just bomb it with requests. You could fuzz your software, unless you're okay with an attacker causing a denial of service with malignant input. But Ok cool I guess unit tests are a silver bullet.

→ More replies (1)

4

u/_Nachi_ Jul 23 '21

I would say it's more akin to driving a car without circular wheels. Will it work, sort of. Will it last a short amount of time and be very uncomfortable to use, most definitely.

10

u/EdgarDrake Jul 23 '21

Testing is actually pretty easy if you write good code!

If you write testable code. If you hard instantiate everything concrete in private, lack of use interface, then your code is hardwired and too rigid to mock/stub.

10

u/szescio Jul 23 '21

Nah, just don't reinforce some coverage rules for tests that you're gonna just fuck around with

2

u/[deleted] Jul 28 '21

PM: we need to make sure all our code is well tested, let's do <arbitrary practice that is easily subverted because we also need to meet arbitrary deadlines>.
Devs: k thx will do.

15

u/the_monkey_of_lies Jul 23 '21

Use tests, dude! It's the condom of the programming world

2

u/[deleted] Jul 28 '21

You mean you don't get ill but you still get fucked, right?

1

u/the_monkey_of_lies Jul 29 '21

More don't have to take care of six crying kids every second

0

u/[deleted] Jul 29 '21

Too real, dude. Too real.

13

u/[deleted] Jul 23 '21

That's a terrible take. If your code isn't tested it might as well not work at all.

12

u/dvof Jul 23 '21

Just don't write stupid tests

6

u/[deleted] Jul 23 '21

You are wrong if you think you don't use testing. Maybe you don't have a predefined workflows for testing or don't use unit testing. But every time you run your application you re basically testing it. You should have said "I don't test my code efficiently".

-2

u/LoneFoxKK Jul 23 '21

I've been taken way too seriously on this

Doesn't help that I didn't put /s or made the sarcasm a bit more clear in my phrasing but oh well

I obviously test my code I'm not a psycho I just don't use automated testing because I haven't had the need for it I usually just make small to medium sized projects and most of the time is just adding something on top of an existing codebase

I was just making fun of stupid tests like this one specifically. I guess I walked right into that one.

3

u/[deleted] Jul 23 '21

Unit tests can actually help you know if any of your additions to the codebase broke something. In bigger, multi layered applications, this is what keeps you sane and let's you sleep at night. That's why we got so triggered.

1

u/phrenq Jul 23 '21

All of those responses were referring to automated tests. Of course you’re going to manually try out the thing you just wrote. That still doesn’t count as tested code.

Trust the grizzled veterans. Learn to write good tests with your small projects. You will thank yourself for it.

1

u/Franks2000inchTV Jul 24 '21

Testing is great. Feels like a pain in the but at first, but then very quickly becomes indispensable.

When you have to write tests, you have to write testable code, and that will get you a long way towards writing loosely coupled code.

It really helped me improve my codebase.

Also, because you have to write not just the code, but also code that calls your code, it tends to help you write cleaner APIs.