TIL - Capturing logs in Elixir tests

Testing logging can be tricky but recently I’ve learned that Elixir’s ExUnit ships with a CaptureLog module that makes it easy to test logging behavior. I was really happy to see this built-in! Let’s say you have a function that processes a template and logs errors when something goes wrong. You want to test both the error handling and ensure the right messages are being logged. Here’s a simplified version of such a function: ...

March 22, 2025 · 3 min · Peter Solnica

Speed Up Your Elixir Testing with Custom Tasks and Key Bindings in Visual Studio Code

Testing is an integral part of software development that ensures your code works as expected. However, running tests can sometimes be a slow and cumbersome process, especially when you’re looking to quickly iterate on your code. I use a “secret” method that allows me to quickly run tests using custom tasks and key bindings in Visual Studio Code (VS Code). This approach is much faster and lighter than other solutions I’ve tried. ...

February 28, 2024 · 3 min · Peter Solnica

Mocking and Ruby

In the “TDD is dead” discussion unit testing and mocking is being mentioned frequently. DHH explicitly expressed how much he dislikes mocks and it seems like many people still connect unit testing with mocking or even confuse the two. In case you missed it Martin Fowler wrote a great article about what should be considered as a unit test. If you’re also confused about mocks and stubs I encourage you to read Mocks Arent’ Stubs. ...

May 22, 2014 · 6 min · Peter Solnica

TDD Is Fun

Today DHH published a blog post about TDD being dead (to him at least). It’s really not that surprising since from what I know (please correct me if I’m wrong) David’s experience is mostly based on building web apps with Rails. I get that, I really do. For me practicing TDD in a rails environment is much harder than when I work on my OSS libraries. There are many reasons why TDD in Rails is just a bit harder than it could be but that’s a big, separate subject. In this post I want to explain that TDD can be fun! ...

April 23, 2014 · 4 min · Peter Solnica

TDD and ActiveRecord in Rails

I don’t have exact numbers but I believe TDD isn’t really popular amongst rails developers. This shouldn’t be a surprise given that the two of the most complex elements in the rails stack, models and controllers, are very convoluted concepts and are simply hard to test. When you’re building a typical rails application most of the business logic lives in the active record models and controllers. Testing controllers in rails is a bit cumbersome but I still encourage people to write tests for them. What about active record models? How do you test them? Is it actually possible to test-drive active record models? ...

January 6, 2014 · 5 min · Peter Solnica