Unit testing framework for Elixir
asyncoptionをtrueしているすると、非同期実行される。つまり、全テストが並列に実行される。
...
use ExUnit.Case, async: true
...
PhoenixでExUnitをwrappingして使われるのでPhoenix - Introduction to Testingを見ておくとPhoenix経由での使い方の概要がわかる
- test/test_helper.exsにてdatabaseのcreate/migrationを行う。mix test毎に行われるので、毎回のテストにてcleanされる。
- test/support配下のmoduleはテスト可能状態にするための機能群で、具体的にはコネクション確立やEctoChangesetのエラー発見?など
- mix commands
## test all files
mix test
## test all files under directory-path
mix test <directory-path>
## test target file
mix test <file-path>
## test target file and target line
mix test <file-path>:<line>
## test with this tag
mix test --only <tag>
EctoのAdapterの1つでテスト専用で使用するもの(Adapterは「適合させるもの」の意味のままの通りで、EctoライブラリとSandbox(PostgreSQL or MySQL)を適合させる。他のAdapterにはMySQLや`PostgreSQLがある)
A pool for concurrent transactional tests.
manual / shared の2modeがある。違いは下記の2点。
| | manualmode(Using allowances) | sharedmode |
| —— | —— | —— |
| cuncurently testable | 可能 | 不可能 |
| explicit allowances | あり | なし |
While both PostgreSQL and MySQL support SQL Sandbox, only PostgreSQL supports concurrent tests while running the SQL Sandbox. Therefore, do not run concurrent tests with MySQL as you may run into deadlocks due to its transaction implementation.