Skip to main content
5 events
when toggle format what by license comment
Mar 4, 2020 at 13:03 vote accept Mansur Ali Koroglu
Mar 4, 2020 at 13:00 comment added Flater @Mansur: The unit test for simpleCalculation mocks getNumber, so this test doesn't actually test getNumber. Therefore it can't (and shouldn't) notice any implementation changes to getNumber. This bug (i.e. changing 2 to "2") should be caught by a test which specifically tests getNumber (which logically speaking cannot be a test which mocks getNumber). It seems like you need a second unit test here, one that tests getNumber.
Mar 4, 2020 at 12:55 comment added Mansur Ali Koroglu Thanks. Covered almost all questions on my mind. Here is my I hope last question. I have function getNumber() { return 2; } and simpleCalculation(number) { return number + getNumber(); } I will unit test simpleCalculation. I will mock getNumber() to make sure it always return 2. After some time I change getNumber function. It will return string "2" now. In reality, simpleCalculation function wont work because int + string isn't possible but my unit test can't detect this because I mocked. How to solve this problem? It is very hard to change the mock in test because it is in tons of test code.
Mar 4, 2020 at 12:30 history edited Flater CC BY-SA 4.0
added 261 characters in body
Mar 4, 2020 at 12:22 history answered Flater CC BY-SA 4.0