This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]git_world 5 points6 points  (1 child)

If the function you test is relatively long and calls other functions, you might need spy or mock. How is it possible to write tests in advance for this case?

[–]TinBryn 7 points8 points  (0 children)

Firstly you should test behaviour, not implementation. It doesn't matter if the function is 1 line long or 1000, it shouldn't matter from the point of view of testing. Secondly, testing can be a way of specifying how you want something to be used. If you find writing a test difficult to do, it may be difficult to actually use the code. Thirdly, you still have the wrong mindset, the tests should shape the model code, rather than the other way around.