Extending Modules

Learn how to use macros to extend modules and build an Assertion framework.

A core purpose of macros is to inject code into modules to extend their behavior, define functions, and perform any other required code generation.

For our Assertion framework, our goal is to extend other modules with a test macro. The macro will accept a test-case description as a string, followed by a block of code where assertions can be made. The description will prefix failure messages to help debug the failing test cases. We’ll also define the run/0 function automatically for the caller so that a single function call can execute all test cases.

Get hands-on with 1200+ tech skills courses.