11# Running tests
22
3- From the terminal, change to the base directory of the problem then execute the tests with:
3+ From the terminal, change to the base directory of the exercise then execute the tests with:
44
55``` bash
66$ mix test
@@ -10,7 +10,7 @@ This will execute the test file found in the `test` subfolder -- a file ending i
1010
1111## Pending tests
1212
13- In the test suites, all but the first test have been skipped.
13+ In test suites of practice exercises , all but the first test have been tagged to be skipped.
1414
1515Once you get a test passing, you can unskip the next one by
1616commenting out the relevant ` @tag :pending ` with a ` # ` symbol.
@@ -24,13 +24,114 @@ test "shouting" do
2424end
2525```
2626
27+ If you wish to run all tests at once, you can include all skipped test by using the ` --include ` flag on the ` mix test ` command:
28+
29+ ``` bash
30+ $ mix test --include pending
31+ ```
32+
2733Or, you can enable all the tests by commenting out the
2834` ExUnit.configure ` line in the test suite.
2935
3036``` elixir
3137# ExUnit.configure exclude: :pending, trace: true
3238```
3339
40+ ## Additional Elixir testing features
41+
42+ ` ExUnit ` and ` mix test ` provide quite a few methods of grouping, tagging & executing
43+ tests and various methods of controlling test execution, much of which is summarized
44+ below.
45+
46+ ### Methods for running specific tests
47+
48+ Documentation:
49+
50+ * [ ` mix test ` documentation] ( https://hexdocs.pm/mix/Mix.Tasks.Test.html )
51+
52+ #### Running tests in a specific file
53+
54+ All tests in a single file may be executed via ` mix test ` by specifying the file:
55+
56+ ``` bash
57+ $ mix test test/< FILE> .exs
58+ ```
59+
60+ > NOTE: ` tagging ` may impact which tests are actually executed using this method.
61+
62+ #### Running individual tests
63+
64+ Individual tests may be executed by referencing a test's line number in the file:
65+
66+ ``` bash
67+ $ mix test test/< FILE> .exs:LINENUM
68+ ```
69+
70+ Multiple tests may be executed by giving multiple line numbers separated by ` : ` .
71+
72+ For example, given a file with the following content with line numbers:
73+
74+ ``` elixir
75+ test " Test 1" do # 1
76+ # test implementation # 2-6
77+ end # 7
78+ # 8
79+ test " Test 2" do # 9
80+ # test implementation # 10-21
81+ end # 22
82+ # 23
83+ test " Test 3" do # 24
84+ # test implementation # 25-35
85+ end # 36
86+ ```
87+
88+ The 1st and 3rd tests can be executed by:
89+
90+ ``` bash
91+ $ mix test test/FILE.exs:1:24
92+ ```
93+
94+ > NOTE: When specifying tests via line numbers, ` tagging ` is ignored.
95+
96+ #### Running groups of tests
97+
98+ Tests may be grouped using ` describe ` :
99+
100+ ``` elixir
101+ describe " short test group description" do
102+ test " test description" do
103+ # test implementation
104+ end
105+
106+ test " another test description" do
107+ # test implementation
108+ end
109+ end
110+ ```
111+
112+ All tests in a group may be executed by referencing its line number in the file,
113+ just like referencing and executing individual tests.
114+
115+ Documentation:
116+
117+ * [ ` describe ` ] ( https://hexdocs.pm/ex_unit/ExUnit.Case.html#describe/2 )
118+
119+ #### Other useful ` mix test ` options
120+
121+ * ` --include ` and ` --exclude ` - runs or doesn't run specific tests based on their ` @tag ` s
122+ * ` --failed ` - runs only tests that failed the last time they ran
123+ * ` --max-failures ` - the suite stops evaluating tests when this number of test failures
124+ is reached
125+ * ` --seed ` - seeds the random number generator used to randomize the order of tests
126+ ` --seed 0 ` disables randomization so the tests in a single file will always be ran
127+ in the same order they were defined in
128+ * ` --stale ` - runs only tests which reference modules that changed since the last
129+ time tests were ran with ` --stale `
130+
131+ Documentation:
132+
133+ * [ ` mix test ` command-line options] ( https://hexdocs.pm/mix/Mix.Tasks.Test.html#module-command-line-options )
134+
34135## Typespecs and Dialyzer (DIscrepancy AnalYZer for ERlang programs)
35136
36137Elixir exercises include a skeleton implementation file in the ` lib `
0 commit comments