r/ProgrammerHumor • • 12d ago

Meme yoDawgIHeardYouLikeUnitTesting

Post image
583 Upvotes

34 comments sorted by

47

u/WisePotato42 12d ago

Me when I was like a month out of college and no one could figure out what work to give me

40

u/sligor 12d ago

Our 40 year old code base is so bloated that we need to test our tests so that we don’t break the tests

14

u/NotAskary 12d ago

One time I added mutation tests to an old project, it was not funny to understand that the coverage was not that good.

12

u/sligor 12d ago

Mutation testing is really underrated 

3

u/TomKavees 12d ago

It is, but it also makes the tests run exponentially longer

7

u/Tidemor 12d ago

Wouldn't be the first time I wrote sanity checks for helper functions for unit tests

1

u/Rojeitor 12d ago

This is the right thing to do. Ofc I won't do that for very simple helpers. "Test helpers are code" => you need to test it.

2

u/SnugglyCoderGuy 12d ago

I wish my 40 year old code had tests.

9

u/Irish_Puzzle 12d ago

What should a unit-test of a unit-test be testing?

19

u/meighty9 12d ago

Mutation testing is a thing. Make minor tweaks to the code under test to validate that the tests fail. If you can flip a 0 to a 1 and the tests don't fail, you likely missed something.

11

u/skys-edge 12d ago

That the test fails when the code behaves incorrectly? Surprising how often that's missed by the tests themselves.

5

u/Mateorabi 12d ago

Purposely passing bad output to it to prove it actually catches mistakes and isn’t just “return (PASS);” under the hood due to laziness or logic flaw. 

2

u/3rdtryatremembering 12d ago

The unit-test.

1

u/Poat540 12d ago

It’s below the pyramid, the part they don’t tell us about

8

u/ChrisWsrn 12d ago

Tests on Unit Tests are typically called Mutation Tests. 

3

u/Irish_Puzzle 12d ago

What should a unit-test of a unit-test be testing?

7

u/kjermy 12d ago

The unit-test of a unit-test should test that the unit-test tests the unit

1

u/Mateorabi 12d ago

It’s unit tests all the way down 

3

u/Dalimyr 12d ago

Read up on mutation tests. Frameworks like Stryker.Net will make small changes to your code and check if any unit tests caught and 'killed' that mutation (because the tests now fail when they previously passed) or if the mutation survived undetected (the line was edited and all tests covering that line still passed).

It might have one mutation that changes if (x >= 0) to if (x > 0), another one that changes the same line to if (x <= 0), another one might change if (x == true || y == false) to if (x != true || y == false) or if (x == true && y == false) and so on and so forth...

You want to run the mutation tests and end up with as few mutations surviving as possible.

It can honestly be quite eye-opening just how many mutations can be present in a single line - a line with a long chain of conditional logic can be especially bad for this. I actually intend on running a demo of mutation testing at my work, and in the demo project I prepped I have one line that on its own is going to start out with 15 mutations that Stryker tried and every last one of them survived. This shows that this one line potentially has a lot of complexity to it and it might be a strong candidate to consider for refactoring.

1

u/flamingspew 12d ago

Lint for cyclomatic complexity

2

u/Beginning-Junket8979 12d ago

I've written plenty of unit tests for reusable test fixtures/functions 🤷‍♂️

3

u/david_l_41873 12d ago

A broken shared fixture can make every test pass for the same wrong reason.

2

u/theFirstHaruspex 12d ago

This boomer ass meme, how dare you

1

u/OneOldNerd 12d ago

Get out.

1

u/joan_bdm 12d ago

Me when 80% test coverage isn't enough and I write extra code to reach 100%

1

u/awesome-alpaca-ace 11d ago

Got to have the unit tests call themselves to get 100%

1

u/hucareshokiesrul 12d ago

It's unit tests all the way down

1

u/a-r-c 12d ago

test my unit lmao

1

u/jewishSpaceMedbeds 12d ago

🤔

But what about testing the tests that test the tests? We need more tests!

1

u/RaymondWalters 12d ago

Unironically did this on one of our test helpers to make sure the helper is helping properly

1

u/apt-maintenance 11d ago

They call me 'The Unit' the way I'm testing their patience

1

u/LittleMlem 10d ago

Quis unit tests ipsos unit tests?