Timeline for Should all class public methods come from an interface?
Current License: CC BY-SA 4.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 16, 2020 at 10:01 | history | edited | CommunityBot | Commonmark migration | |
| Aug 8, 2018 at 10:51 | comment | added | David Arno | @Flater, Yet again, you are the one that bought up both OOP and its problems. Yet once again, you then seek to criticise me for talking about them? Very odd. | |
| Aug 8, 2018 at 10:48 | comment | added | Flater | @DavidArno: As mentioned on other comments you posted, this is neither the time nor the place for anti-OOP soapboxing. | |
| Aug 8, 2018 at 10:31 | comment | added | David Arno | @Flater, If OOP principles are forcing you down the path of bad practice, stop using those OOP principles. If your take on OOP is forcing you to mix state and functionality and to then have to mock everything to facilitate testing, then those mocks are a symptom of a problem; not a solution. So don't mix state and functionality and then you'll need a lot less mocks. | |
| Aug 8, 2018 at 10:29 | comment | added | Ewan | @flater my confusion on the first sentence is that you imply that mocking the public methods enables testing of the same method. surely you mean enables testing of other classes which call the method? | |
| Aug 8, 2018 at 10:14 | history | edited | Flater | CC BY-SA 4.0 | added 273 characters in body |
| Aug 8, 2018 at 10:12 | comment | added | Flater | @DavidArno: Ideally, all of your code should be stateless and fast and so should need zero mocking. Either you're advocating that no testing should take place, or you're using an overly selective definition of "mocking". In this case, it means "testable", i.e. defined in an interface (or, as per OP's question, made virtual) so that it can be mocked during testing. I will amend the answer to remove the ambiguity. all of your code should be stateless OOP principles conflict with a stateless coding approach. | |
| Aug 8, 2018 at 10:11 | comment | added | Ewan | @DavidArno its that sentence which prompted me to write my answer. Not sure I understand the meaning. Maybe Flater can clarify it? | |
| Aug 8, 2018 at 10:09 | comment | added | David Arno | Downvoting this due to "Ideally, you should test all public methods, which does indeed mean that all public methods should be mockable". No. Ideally, all of your code should be stateless and fast and so should need zero mocking. In practice, an app with zero state would be useless, so some state is needed and so some mocking is needed. Keep those mocks to an absolute minimum though. | |
| Aug 8, 2018 at 10:07 | comment | added | Flater | @Fabio (and DavidArno): I wish you luck with your "my way or the highway" approach. I have yet to come across a single employer (15+ so far as a consultant) where budgets and deadlines were freely choosable by the developer. I'm all for considering the technical need for testing, but your hardline stances will simply render a developer an undersirable hire as opposed to making the project more workable. | |
| Aug 8, 2018 at 10:07 | comment | added | David Arno | @Fabio, +1. Use TDD; write tests before you write code. Tests are non-negotiable. If you can't write tests, you can't write code. If your management won't let you do your job properly, "sack them" by leaving and getting a job in a sane company. | |
| Aug 8, 2018 at 10:06 | comment | added | Fabio | @Ewan, if you cannot change company - change company ;) | |
| Aug 8, 2018 at 10:05 | comment | added | Ewan | ..unless you want to keep your job | |
| Aug 8, 2018 at 10:03 | comment | added | Fabio | This can sounds cliche, but worth to mention: Testing is part of developer's work process, you shouldn't ask permission for writing unit tests, same way as you not asking permission for using polymorphism over switch statements ;) | |
| Aug 8, 2018 at 7:51 | history | answered | Flater | CC BY-SA 4.0 |