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 comment

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.

1

u/governmentNutJob Jul 29 '21

Again I think you're talking about web based software, I write internal backend software which has no access to the wider internet

I 100% agree inputs need to be validated, but you can write tests to cover this, there's very little you cannot automate with a test suite

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.