Välj en sida

A couple of days ago we hosted a Elixir Meetup here at Bonnier Broadcasting. About 40 people turned up to eat some pizza, have some beer and listen to our developers Daniel and Anna talking about their experiences with Elixir. And as it happens, it was 4 years, almost to the day, that we did our first Elixir commit 🙂

I asked both Anna and Daniel to write a summary of their talks.

 

Anna – Reinventing the wheel: using mocks in tests

At Bonnier Broadcasting we value the importance of a good test suite and thus put a lot of effort into making our tests clean, maintainable and readable. Sometimes when we test our applications, we need to mock certain dependencies. It took us a good deal of trial and error to land at the testing approach we have this day.

We started with a quick and easy approach of substituting modules under test with mock modules with the help of Elixir’s configuration files. We soon found it to not be particularly maintainable and it did not make our tests descriptive. We experimented with different solutions and ended up writing our own library called Fake. It is open source, feel free to check it out here: httpss://github.com/TV4/fake . Even though it helped us improve our tests, there was a downside to it: we could not use Fake in controller level tests and had to resort to substituting modules with the help of configuration again. Mixing two approaches to mocking did feel like not the right way to go, so after some research we ended up rewriting our tests using Mox (httpss://github.com/plataformatec/mox), which happens to implement the mocking principles backed by the Elixir community.

We made quite a journey searching for the way to test the applications that feels right. We walked in circles there for a while, but we don’t see it as a negative experience. Sometimes it’s good to slow down and reflect about how you can improve your code base.

 

Daniel – Ecto: scratching the surface

Scratching the surface demonstrates how convenient it is for data to be modeled, inserted and queried with Ecto – the premier database library for Elixir.

Touching upon Ecto’s main areas; migrations, schemas,     changesets and queries, as well as composition when seeding data.

 

 

For those of you who missed out on this meetup, we’ll be back with more!