Skip to content

Commit 7b71138

Browse files
authored
Add Mermaid graph about ExUnit processes (#14372)
1 parent f6f7d30 commit 7b71138

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/ex_unit/lib/ex_unit/case.ex

+31
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,37 @@ defmodule ExUnit.Case do
301301
302302
As with other tags, `:tmp_dir` can also be set as `@moduletag` and
303303
`@describetag`.
304+
305+
## Process Architecture
306+
307+
An ExUnit test case uses several processes when it runs. These are illustrated below.
308+
309+
```mermaid
310+
sequenceDiagram
311+
participant runner as ExUnit Case
312+
runner->>runner: Run setup_all callbacks
313+
314+
loop Each test
315+
create participant test as Test Process
316+
runner->>test: Spawn
317+
test->>test: Run setup callbacks
318+
test->>test: Run test
319+
destroy test
320+
test-xrunner: Exits
321+
runner->>runner: Run on_exit callbacks
322+
end
323+
```
324+
325+
1. First, all `ExUnit.Callbacks.setup_all/1` callbacks run in a single process, sequentially,
326+
in the order they were defined.
327+
328+
2. Then, a new process is spawned for the test itself. In this process, first all
329+
`ExUnit.Callbacks.setup/1` callbacks run, in the order they were defined. Then,
330+
the test itself is executed.
331+
332+
3. After the test exits, a new process is spawned to run all `ExUnit.Callbacks.on_exit/2`,
333+
in the reverse order they were defined.
334+
304335
"""
305336

306337
@type env :: module() | Macro.Env.t()

0 commit comments

Comments
 (0)