|
|
|
|
|
by mavelikara
2985 days ago
|
|
> not because they need any of the mocking features as such but because it takes up fewer lines on the screen Why is this a bad thing? How is this different from, say, using Template Haskell? > It means you can no longer e.g. extract common expressions, because they don't necessarily mean the same thing; if you have some common mock setup code you can't just blindly automatically extract method, you have to think carefully about when the mocks get instantiated and when the expectations are set. I have never found the existence of tests using mocks being a hindrance to refactoring in Java. Can you provide a more specific example? PS:
> How is it not reflection ("the ability of a computer program to examine, introspect, and modify its own structure and behavior at runtime")? Agree that it is reflection, by that definition. |
|
Because it shows the language could be a lot better. A common, basic task shouldn't be so much easier outside the language (via reflection) than inside it.
> How is this different from, say, using Template Haskell?
It's the same thing. To the extent that people feel the need to use Template Haskell to do basic and common things, something is very wrong with Haskell.
> I have never found the existence of tests using mocks being a hindrance to refactoring in Java. Can you provide a more specific example?
I mean you can't refactor the test itself. Just basic things like: if you do expect(methodOne(matches("someComplexRegex"))) ; expect(methodTwo(matches("someComplexRegex"))), if you try to pull matches("someComplexRegex") out as a variable you'll break your test (you have to make it a function instead). You can't move an expect() above or below another method call without checking to see whether that was the method it was testing. Individually these things are trivial, but they add up to a chilling effect where people don't dare to improve mock-based tests a little as they work on them, so they end up as repetitive code with subtle variations, just like main code would if you never refactored it.