ExUnit checking if Enum.at is called?

Why do you need to check if Enum is called? If you do so, you will be asserting how the function is implemented and not how the function behaves. That’s undesirable because you may change the implementation, for example by calling Enum.fetch instead of Enum.at, and now your tests break even when the code exhibits the same behaviour.

The question you want to ask yourself is which properties you expect the code to exhibit by calling Enum.at and how you can assert those properties through testing without relying on mocks.

4 Likes