List Comprehensions
Explore how to leverage list comprehensions in Elixir unit tests for handling multiple similar cases distinctly. Understand applying module attributes for test data isolation and using metaprogramming with unquote in ExUnit tests to improve clarity and maintainability.
Setting module attributes in test files
Now that our first test uses a fixture, we’ll add tests focusing on specific values in the weather API response. Since the module under test (SoggyWaffle.WeatherAPI.ResponseParser) is focused on translating data specific to an external API into internal data, the module must have a lot of knowledge specific to that API. This shows up in the form of all the various weather condition IDs at the top of the module.
Our tests will have to have that same level of knowledge so that they can test the code thoroughly. This means adding a copy of all of the IDs to our test file.
Note: It may seem like a good idea to put them somewhere where both the ...