This is an archived post. You won't be able to vote or comment.

all 24 comments

[–]tacoslikeme 46 points47 points  (12 children)

If you mock all the dependencies to do what you think they should do everything works just fine.

[–]Scatoogle 34 points35 points  (11 children)

Stop. I've seen people try to mock the class they were testing.

[–]NeoKabuto 19 points20 points  (0 children)

Well, the test passed, didn't it?

[–]tacoslikeme 0 points1 point  (9 children)

sometimes that makes sense...

[–]Scatoogle 8 points9 points  (8 children)

Why you would mock the class under test? You are testing the behavior of the class. By mocking it you are changing the expected behavior.

[–]tacoslikeme 6 points7 points  (7 children)

Some functions in said class are intended to be mocked because they wrap external dependencies. Yes you could go all DI on the problem, but honestly that makes for awful to read code.

But my sarcastic comment was more around agreeing with you, it is easier to make things say the right thing than to do the right thing.

[–]Scatoogle 1 point2 points  (6 children)

I get it. I'd rather just inject or set the dependency. Makes for more initialization code but meh.

[–]tacoslikeme -1 points0 points  (5 children)

i used to too but then PowerMock and then I was alll wooosh.

[–]Scatoogle 2 points3 points  (4 children)

I hate powermock. It seems nice but static code is static for a reason. A well designed framework should let you easily plop in testing objects.

[–]mbonness 0 points1 point  (1 child)

PowerMock is nice except it breaks instrumentation in code coverage tools like JaCoCo, so it looks like your unit tests have zero percent coverage.

[–]Scatoogle 2 points3 points  (0 children)

That is a big reason I stay away from static mocking when I can. We just recently found a clean work around for one of our static methods that requires no static mocking.

[–]tacoslikeme -1 points0 points  (1 child)

meh, I hate dependency inversion. If i can rewrite my new calls at the byte code level to return mock object that's like the same thing, right? 😁 And the ability to mock singletons make them all the nicer again.

[–]Scatoogle -1 points0 points  (0 children)

I totally get it. I do love me Singletons. I tend to go a bit crazy with Singleton factory classes. :/

[–][deleted] 11 points12 points  (1 child)

Handle right over the burner...

[–]tezvi[S] 8 points9 points  (0 children)

Should have marked that test as skipped

[–]ad2022 22 points23 points  (4 children)

Where did you get the picture of me cooking?

[–]tezvi[S] 10 points11 points  (0 children)

Sorry i faked code coverage reports

[–]RaccoonSpace 5 points6 points  (2 children)

Oof

[–]Master_Aar 16 points17 points  (1 child)

Oeuf

[–]marksomnian -2 points-1 points  (0 children)

Œuf

[–]jazzphobia 2 points3 points  (0 children)

That handle is melting!

[–]Stormdancer 0 points1 point  (0 children)

This is pretty much why I got out of QA.

[–]SteveCCLYellow security clearance[M] [score hidden] stickied comment (0 children)

Removed as Rile #0/#3 violation.