News for hackers. Stuff that matters.
Re:Generating a Java program with 90% less code by t-writescode on Wednesday December 04, 2019 @12:38PM (#21704539)
A common pattern to get around this situation is to use mocking frameworks to fake those calls without using interfaces. It’s in the air whether this is better or worse in the general lifespan of a piece of code; but, there are alternatives.
Re:Generating a Java program with 90% less code by taco_emoji on Wednesday December 04, 2019 @01:01PM (#21704881)
How does that work in a static language? In most (all?) static languages, you'd need an interface or virtual method in order to on-the-fly generate a class that implements the mocked functionality.
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.
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.