forked from elixir-lang/elixir-lang.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExUnit.html
More file actions
212 lines (161 loc) · 5.97 KB
/
Copy pathExUnit.html
File metadata and controls
212 lines (161 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html>
<head>
<title>ExUnit</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
relpath = '';
if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
if (window.top.frames.main) document.body.className = 'frames';
</script>
<div id="content">
<h1>
ExUnit
</h1>
<div id="moduledoc" class="docstring">
<p>Basic unit test structure for Elixir.</p>
<h2>Example</h2>
<p>A basic setup for ExUnit is shown below:</p>
<pre><code># File: assertion_test.exs
# 1) Start ExUnit. You can pass some options as argument (list below)
ExUnit.start
# 2) Next we create a new TestCase and use ExUnit.Case
defmodule AssertionTest do
# 3) Notice we pass async: true, this runs the test case in parallel
use ExUnit.Case, async: true
# 4) A test is a method which name finishes with _test
def test_always_pass do
assert true
end
# 5) It is recommended to use the test macro instead of def
test "the truth" do
assert true
end
end
</code></pre>
<p>To run the test above, all you need to to is to run the file
using elixir from command line. Assuming you named your file
assertion_test.exs, you can run it as:</p>
<pre><code>bin/elixir assertion_test.exs
</code></pre>
<h2>Assertions</h2>
<p>Check ExUnit.Assertions for assertions documentation.</p>
<h2>User config</h2>
<p>When started, ExUnit automatically reads a user configuration
from the following locations, in this order:</p>
<ul>
<li>$EXUNIT_CONFIG environment variable</li>
<li>$HOME/.ex_unit.exs</li>
</ul>
<p>If none found, no user config will be read.</p>
<p>User config is an elixir file which should return a keyword list
with ex_unit options. Please note that explicit options passed
to start/1 or configure/1 will take precedence over user options.</p>
<pre><code># User config example (~/.ex_unit.exs)
[formatter: ExUnit.Formatter.ANSI]
</code></pre>
</div>
<a href="https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit.ex#L1" target="_blank" class="view_source">Source</a>
<h2>Functions summary</h2>
<ul class="summary">
<li>
<span class="summary_signature">
<a href="#after_spawn/1">after_spawn/1</a>
</span>
</li>
<li>
<span class="summary_signature">
<a href="#configure/1">configure/1</a>
</span>
</li>
<li>
<span class="summary_signature">
<a href="#run/0">run/0</a>
</span>
</li>
<li>
<span class="summary_signature">
<a href="#start/1">start/1</a>
</span>
</li>
<li>
<span class="summary_signature">
<a href="#stop/1">stop/1</a>
</span>
</li>
<li>
<span class="summary_signature">
<a href="#user_options/1">user_options/1</a>
</span>
</li>
</ul>
<div id="functions_details" class="details_list">
<h2>Functions</h2>
<div class="detail">
<p class="signature" id="after_spawn/1">
<strong>after_spawn(callback)</strong>
</p>
<div class="docstring"><p>Registers a callback to be invoked every time a
new ExUnit process is spawned.</p>
</div>
<a href="https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit.ex#L130" target="_blank" class="view_source">Source</a>
</div><div class="detail">
<p class="signature" id="configure/1">
<strong>configure(options)</strong>
</p>
<div class="docstring"><p>Configures ExUnit.</p>
<h2>Options</h2>
<p>ExUnit supports the following options given to start:</p>
<ul>
<li><p><code>:formatter</code> - The formatter that will print results.
Defaults to <code>ExUnit.CLIFormatter</code>;</p></li>
<li><p><code>:max_cases</code> - Maximum number of cases to run in parallel.
Defaults to <code>:erlang.system_info(:schedulers_online)</code>;</p></li>
</ul>
</div>
<a href="https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit.ex#L122" target="_blank" class="view_source">Source</a>
</div><div class="detail">
<p class="signature" id="run/0">
<strong>run()</strong>
</p>
<div class="docstring"><p>API used to run the tests. It is invoked automatically
if ExUnit is started via <code>ExUnit.start</code>.</p>
<p>Returns the number of failures.</p>
</div>
<a href="https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit.ex#L140" target="_blank" class="view_source">Source</a>
</div><div class="detail">
<p class="signature" id="start/1">
<strong>start(options // [])</strong>
</p>
<div class="docstring"><p>Starts up ExUnit and automatically set it up to run
tests at the VM exit. It accepts a set of options to
configure <code>ExUnit</code> (the same ones accepted by <code>configure/1</code>).</p>
<p>In case you want to run tests manually, skip calling this
function and rely on <code>configure/1</code> and <code>run/0</code> instead.</p>
</div>
<a href="https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit.ex#L74" target="_blank" class="view_source">Source</a>
</div><div class="detail">
<p class="signature" id="stop/1">
<strong>stop(_state)</strong>
</p>
<div class="docstring"></div>
<a href="https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit.ex#L98" target="_blank" class="view_source">Source</a>
</div><div class="detail">
<p class="signature" id="user_options/1">
<strong>user_options(user_config // nil)</strong>
</p>
<div class="docstring"><p>Returns the configured user options.</p>
</div>
<a href="https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit.ex#L94" target="_blank" class="view_source">Source</a>
</div>
</div>
</div>
</body>
</html>