Timeline for Should we design our code from the beginning to enable unit testing?
Current License: CC BY-SA 4.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 1, 2019 at 9:55 | comment | added | Thorbjørn Ravn Andersen | Also, regression tests are very important. Are they in scope for the team? | |
| Feb 1, 2019 at 0:22 | comment | added | Thorbjørn Ravn Andersen | @Lee Small steps. The bare minimum may be more than you think when the code rises above trivial. Also the design you do when implementing the whole thing at once may again be less optimal because you make assumptions on how it should be made without having written the tests yet that demonstrate it. Again remember, the code should fail at first. | |
| Jan 31, 2019 at 15:02 | comment | added | Lee | I understand these premises, but it does seem odd to write the bare minimum when you already have a very good idea of a bit further down the line, so why not add the test and then add the code to pass that's more mature? The best answer I've seen so far about why you should write the absolute minimum is because you can't be sure whether your tests can actually fail, otherwise. Although I like Robert Harvey's not-so-purist view of TDD. | |
| Jan 30, 2019 at 13:31 | comment | added | Thorbjørn Ravn Andersen | @Lee This is the design as such. The final product may be much more complex than what is necessary to have the test pass (you don't need an Oracle database connection to check 2 + 2) and then you identify your dependencies and can recursively make clean interfaces for those too. The understanding that at any given point minimize the amount of knowledge the code needs to have is crucial in making clean API's across the application. | |
| Jan 30, 2019 at 11:21 | comment | added | R. Schmitz |
@Lee Ultimately, your tests will end up being the documentation of what your code does, except it's documentation that checks if it is fulfilled itself, instead of just being ink on paper. Also compare with this question - A method CalculateFactorial that just returns 120 and the test passes. That is the minimum. It's also obviously not what was intended, but that just means you need another test to express what was intended.
|
|
| Jan 30, 2019 at 11:10 | comment | added | R. Schmitz |
@Lee "minimum code to pass"... well, this might sound a bit dumb, but it's literally what it says. E.g. if you have a test UserCanChangeTheirPassword, then in the test you call the (not yet existing) function to change the password and then you assert that the password is indeed changed. Then you write the function, until you can run the test and it does neither throw exceptions nor have a wrong assert. If at that point you have a reason to add any code, then that reason goes into another test, e.g. UserCantChangePasswordToEmptyString.
|
|
| Jan 30, 2019 at 8:20 | comment | added | Lee | We have a problem with TDD as well, namely, what constitutes "minimum code to pass". I demonstrated to the team this process and they took exception to not just writing what we have already designed - which I can understand. The "minimum" doesn't seem to be defined. If we write a test and have clear plans and designs, why not write that to pass the test? | |
| Jan 29, 2019 at 15:24 | history | answered | Thorbjørn Ravn Andersen | CC BY-SA 4.0 |