Search⌘ K
AI Features

Integration Testing

Explore how to apply integration testing techniques to Elixir libraries that use metaprogramming macros, specifically testing the behavior of generated code. Understand the testing strategy to cover macro-generated functions like those in the Translator library, handling cases such as multiple locales, nested translations, interpolation, and error cases. This lesson helps you ensure that your metaprogramming libraries work correctly at the integration level.

We did advanced metaprogramming with our Mime and Translator libraries in the lesson Advanced Compile-Time Code Generation of Chapter 4.

Macro-driven libraries that generate large amounts of code are best tested at the integration level.

In this lesson, we’ll explore Integration testing and we will apply it to the libraries we’ve written.

Testing our generated code, not our code generation

Integration testing means we test our library behavior at the top level. When we give an input, we expect an output. We aren’t concerned with testing the individual subcomponents. Testing macro-generated code in this way is effective because it’s very difficult to isolate the AST transformation steps along the way. Instead, we use macros to generate code. Then, we test the expected behavior of the code, not the code-generation process itself.

We will execute integration testing by writing a test suite ...