r/ProgrammerHumor • • Jul 20 '18

Every Time

Post image
52.2k Upvotes

749 comments sorted by

View all comments

Show parent comments

11

u/rangeDSP Jul 20 '18

If your testing can't catch errors like these it implies that at least one of the following is truel:

  1. The tests are badly written

  2. The code isn't easily testable

  3. if(2==true), then there are messy dependency issues in the code

8

u/_Fibbles_ Jul 20 '18 edited Jul 20 '18

Sometimes code is not easily testable because it's non deterministic by design. That's got nothing to do with messy dependencies.

I think we can all agree tests are necessary and helpful but sometimes the fervour of the "everything must be unit tested" brigade makes me feel like they're either:

0. Fresh out of university and don't know any better.

  1. High up enough in the management chain that they don't write code anymore and don't have to deal with the challenges of what they're asking for.

5

u/rangeDSP Jul 20 '18

In this case the comment I was replying to was doing a build, surely that should be deterministic?

I'm totally not in the 100% test coverage camp. We usually do 40%, most of which are business rules.

Yes I worded that badly, meant to say not being able to write testable code is a code smell that implies possible dependency mess, but is not direct cause / effect.

4

u/_Fibbles_ Jul 20 '18

Yeh, building should definitely be deterministic. Sorry, didn't mean to have a go. It's just the 'testing solves everything' mentality really winds me up.

4

u/rangeDSP Jul 20 '18

Fair, and I get riled up by people saying they don't do tests at all because it's useless.

Guess we are both in the happy middle ground? Being pragmatic about philosophies.

2

u/[deleted] Jul 20 '18

I recently had a plumbing issue in my apartment. The apartment ultimately sent 4 different plumbers over. The first 3 all walked in knowing what was wrong and executed a fix. They all failed. The fourth guy walked in and said, "I really need to reproduce the issue before I can fix it." He fixed it.

I know I'm blurring the semantic lines here, but I too am a fan of "pragmatic" testing.

1

u/Allways_Wrong Jul 21 '18

Seems like an appropriate place to ask “How can I adequately test Active Record type classes?”

Often the data stack I need to setup before I get to my test data is very, very, very time consuming, and painful (enterprise). The alternative is, er, hard-coding data through a mock class or similar, but then what’s the point?

If it’s something I’m going to be working with a lot I will put in effort to automate the entire data stack, but more often than not it’s something I’ll throw over the fence and never see again. And setting up all that data to test it correctly will take up 90% or more of the time. It often takes up most of the time just setting it up manually.

2

u/motioncuty Jul 20 '18

Now I have to right tests for my jenkins builds!? When does it end?

4

u/rangeDSP Jul 20 '18

Not necessary to write a test, but builds should be part of your continuous integration process, after all the unit tests are run, and if build fails it just won't move from dev to UAT release.

If your builds aren't deterministic there's something wrong with the build tool, your configuration, or the build machine. That definitely needs to be fixed.

1

u/motioncuty Jul 20 '18

If your builds aren't deterministic

Lol. they always seem to fail when we reboot the servers.

1

u/rangeDSP Jul 20 '18

Perhaps have the build process retry if it fails the first time, problem solved? ¯_(ツ)_/¯

2

u/motioncuty Jul 20 '18

Oh I'm just bitching about dysfunction in a system too big to fix, in areas I'm not supposed to touch.

1

u/[deleted] Jul 20 '18

-every large company dev job

1

u/LimbRetrieval-Bot Jul 20 '18

You dropped this \


To prevent anymore lost limbs throughout Reddit, correctly escape the arms and shoulders by typing the shrug as ¯\\_(ツ)_/¯ or ¯\\_(ツ)_/¯

^^Click here to see why this is necessary

1

u/rangeDSP Jul 20 '18

Good bot

1

u/squngy Jul 20 '18

if(2==true), then there are messy dependency issues in the code

javascript: I don't get it...

1

u/rangeDSP Jul 20 '18

Actually that would've been fine in JavaScript, didn't want to go into truthy or falsey debate, your linter would complain though 😛