Livebook notebooks are a form of executable documentation - documentation that can be verified by running it.
What is Executable Documentation?
Traditional documentation (README, wiki, blog posts) contains code snippets that are copied and pasted by readers. There's no guarantee the code still works.
Executable documentation is different: the code is run automatically, ensuring it always works.
Livebook as Executable Documentation
Livebook's .livemd format is perfect for executable documentation because:
- Readable as plain text - it's Markdown
- Version controllable - diff-friendly text format
- Runnable - Livebook can execute it directly
- Testable -
livebook_testcan verify it in CI
The livebook_test Approach
livebook_test treats notebooks as test artifacts:
- Discover - Find all
.livemdfiles in your project - Export - Convert them to standalone Elixir scripts
- Run - Execute each script and check for errors
- Report - Summarize which notebooks pass and fail
This creates a feedback loop: documentation that breaks is caught immediately.
Best Practices
Keep Notebooks Simple
Notebooks used as executable documentation should:
- Avoid long-running computations
- Avoid external service dependencies (or mock them)
- Use deterministic outputs
- Keep
Mix.installdependencies minimal
Structure for Testability
# My Feature Guide
## Setup
```elixir
Mix.install([{:my_lib, "~> 0.5"}])
```
## Basic Usage
```elixir
MyLib.hello("world") |> IO.puts()
```
## Advanced Usage
```elixir
MyLib.configure(option: :value)
```Separate Interactive from Testable
Some Livebook features (inputs, smart cells, Kino widgets) are interactive and won't work in a headless test. Keep interactive elements in dedicated "demo" notebooks, separate from the "testable" documentation notebooks.
Including Notebooks in ExDoc
Livebook .livemd files can be included in ExDoc's extras independently of
livebook_test. Add them to mix.exs:
docs: [
extras: [
"README.md",
"examples/basic.livemd"
]
]ExDoc will render the .livemd files as formatted documentation pages.