Re:Generating a Java program with 90% less code
by chinhodado on Wednesday December 04, 2019 @01:32PM
(#21705308)
Not entirely sure what you meant, but in Java/C# you can easily mock out a concrete class with a mock library, like Mockito. No interface required.
[ Parent
| on HN ]
Re:Generating a Java program with 90% less code
by GordonS on Wednesday December 04, 2019 @01:46PM
(#21705511)
There are plenty of mocking frameworks for C# (Moq, FakeItEasy, etc), but for all but the most trivial classes, you generally need to use an interface or mark methods as virtual.
It's one of the reasons I tend to minimise my use of mocks as much as possible.
Re:Generating a Java program with 90% less code
by chinhodado on Wednesday December 04, 2019 @02:03PM
(#21705731)
It's the same with Java where it's very hard/not possible to mock final methods. It's just that methods in Java are virtual by default so it's less "in the way" when you need to mock something.
Re:Generating a Java program with 90% less code
by apta on Wednesday December 04, 2019 @05:38PM
(#21707995)
What do you use instead of mocks when testing?
Re:Generating a Java program with 90% less code
by GordonS on Wednesday December 04, 2019 @06:10PM
(#21708186)
Real instances of the dependant class.
A "unit test purist" would likely shun this, but I take more of a realist approach; in many real-world cases, mock-heavy tests make for brittle tests that don't give confidence of correctness.
I tend to focus on integration tests, as I find these provide the most value while still executing very quickly (depending on the stack, obv).
That doesn't mean I don't use unit tests, or that I never use mocks - I just use mocks very sparingly.