Testing the Information System

To warm up, we’re going to start our tests with our independent caching layer. Since our cache is made up of a standalone genserver, we can test it in isolation. It’s a good place to start because our cache can do two things: fetch and put.

Testing Our Cache

For the most part, testing our cache will work like testing any other service. We’ll create a cache and try some fetches and puts. Then we’ll use asserts to check what actually happened against our expectations. Let’s begin with a few basic tests and then we can handle corner cases for timeouts and shutdown. Shift into the apps/info_sys directory and then make tests/cache_test.exs look like this:

Get Programming Phoenix 1.4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.