Timeline for Should we design our code from the beginning to enable unit testing?
Current License: CC BY-SA 4.0
17 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 7, 2019 at 23:25 | audit | First posts | |||
| Feb 7, 2019 at 23:26 | |||||
| Feb 1, 2019 at 12:15 | comment | added | Anders Forsgren | Designs can definitely suffer from "Test induced damage". Usually testability improves design: You notice when writing tests that something can't be fetched but must be passed in, making for clearer interfaces and so on. But occasionally you'll stumble across something that requires an uncomfortable design only for testing. An example could be a test-only constructor required in your new code due to existing third party code that uses a singleton for example. When that happens: take a step back and make an integration test only, instead of damaging your own design in the name of testability. | |
| S Feb 1, 2019 at 8:39 | history | suggested | Brian McCutchon | CC BY-SA 4.0 |
spelling and grammar
|
| Feb 1, 2019 at 7:10 | review | Suggested edits | |||
| S Feb 1, 2019 at 8:39 | |||||
| Jan 31, 2019 at 14:37 | comment | added | Lee | @Ewan It's not me who needs to be convinced. If it were just me I'd have started typical unit testing practices by now. The bottom line is: some on the team don't like the idea of designing code in any way to allow usual unit testing practices - i.e. the ability to mock dependencies, which is why strange ideas like using reflection to crowbar in the mocks has been raised by some. | |
| Jan 31, 2019 at 13:28 | comment | added | Ewan | @sulthan in 2019 I think we can still argue for days about whether a given test is unit/integration/e2e/ui/BDD etc etc It sounds from the OP that we are still at 'some passing tests' level of convincing | |
| Jan 31, 2019 at 7:32 | comment | added | Sulthan | I strongly disagree with the statement that writing unit tests is always a good thing. Unit tests are good only in some cases. It's silly to use unit tests to test frontend (UI) code, they are made to test business logic. Also, it's good to write unit tests to replace missing compilation checks (e.g. in Javascript). Most frontend-only code should write end-to-end test exclusively, not unit tests. | |
| Jan 30, 2019 at 17:01 | history | edited | Ewan | CC BY-SA 4.0 |
added 385 characters in body
|
| Jan 30, 2019 at 12:30 | comment | added | Konrad Rudolph | @DocBrown That’s a tiny part of this answer (a single bullet point). The rest is relevant regardless of whether it’s for new code or existing one. The accepted answer, by contrast, is quite seriously flawed, as my comment there explains. | |
| Jan 30, 2019 at 12:10 | comment | added | Doc Brown | @KonradRudolph: I guess missed the point where the OP added that this question was about designing new code, not changing existing one. So there is nothing to break, which makes most of this answer not applicable. | |
| Jan 30, 2019 at 3:44 | comment | added | Wes Toleman | @Lee A unit test should test a unit of functionality, which may or may not correspond to a class. A unit of functionality should be tested at its interface (which may be the API in this case). Testing may highlight design smells and the need to apply some different/more levelisation. Build your systems from small composable pieces, they will be easier to reason about and test. | |
| Jan 29, 2019 at 20:24 | comment | added | Konrad Rudolph | This is a much better answer than the accepted one. The imbalance in votes is dismaying. | |
| Jan 29, 2019 at 12:17 | comment | added | Ewan | I think the question is fine as it stands and i cover your senario breifly with point 2. It does sound more like a push back against unit testing rather than a legitimate concern when its a green field project though | |
| Jan 29, 2019 at 12:10 | comment | added | Lee | I must have phrased it badly. So we're still designing the system and this has come out of those meetings. So it's basically "tailoring the code we're about to write to be testable seems like a code smell" ... which.. reading it back seems quite ridiculous. | |
| Jan 29, 2019 at 12:08 | comment | added | Ewan | I wouldn't change the question now. But yeah, you can't modify code that hasn't been written yet. | |
| Jan 29, 2019 at 12:05 | comment | added | Lee | I like your point that's essentially about the value of tests. Unit testing the Web API most likely will not provide much value. By the way, this isn't a legacy system, it's a new greenfield project. Should I rephrase the question? | |
| Jan 29, 2019 at 11:50 | history | answered | Ewan | CC BY-SA 4.0 |