Timeline for Unit Testing - should / how should I write tests to cover new code that doesn't affect the interface of a method?
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 30, 2022 at 14:31 | comment | added | Ewan | as long as you are commenting, or otherwise indicating though method names or whatnot, that the check is that "an email is sent" and the implementation is a bit hacky then the test is a good spec for all implementations of the object | |
| Dec 30, 2022 at 14:28 | comment | added | Ewan | a test which just checks that x y and z dependencies have been called is a code smell, but in the case of checking for side effects and limiting the scope to a unit test and ignoring possible refactoring to not use dependencies for things like logging? | |
| Dec 30, 2022 at 14:23 | comment | added | Ewan | i dont think the distinction between different types of mock has much relevance these days. re the log function, I think there is a separate argument about "where to log", but in your question the log call might as well be the send or getuser, the problem is that the overall function returns a null and has these side effects which you want to test. If you define in the test that "sending an email" == "call emailService.Send" or "using this fake emailer a file should be written to" or "using this actual email service, check my email" | |
| Dec 30, 2022 at 13:00 | comment | added | gbro3n | See Martin Fowlers article on use of Test Doubles as compared to Mocks martinfowler.com/articles/mocksArentStubs.html | |
| Dec 30, 2022 at 13:00 | comment | added | gbro3n | I agree that it seems that some verification of the email send is needed. Regarding the logging, I don't see how the _db. LogEmailSend could be done anywhere else. I've linked to the article regarding test behaviour, not implementation detail. It suggests that only the public API should be testing, leaving me to infer that the verification of the internal behaviour should be left to integration testing. A potential compromise would be the use of Test Doubles over Mocks, so I can test the state of a test double rather than verifying specific function calls. | |
| Dec 30, 2022 at 12:05 | history | edited | Ewan | CC BY-SA 4.0 | added 620 characters in body |
| Dec 30, 2022 at 11:54 | history | answered | Ewan | CC BY-SA 4.0 |