-
Notifications
You must be signed in to change notification settings - Fork 2
/
installing.html
218 lines (155 loc) · 12.1 KB
/
installing.html
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
213
214
215
216
217
218
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Expectations by jaycfields</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
<script src="javascripts/scale.fix.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">
<header>
<h1 class="header">Expectations</h1>
<p class="header">a minimalist's unit testing framework</p>
<ul>
<li><a class="buttons" href="index.html">Home</a></li>
<li><a class="buttons" href="installing.html">Installing</a></li>
<li><a class="buttons" href="introduction.html">Introduction</a></li>
<li><a class="buttons" href="advanced.html">Advanced</a></li>
<li><a class="buttons" href="collections.html">Collections</a></li>
<li><a class="buttons" href="templating.html">Expect More</a></li>
<li><a class="buttons" href="odds-ends.html">Odds & Ends</a></li>
<li><a class="buttons" href="in-context.html">Around Each</a></li>
<li><a class="buttons" href="before-run-hook.html">Around Suite</a></li>
<li><a class="buttons" href="state-warnings.html">State Warnings</a></li>
<li><a class="buttons" href="redef-state.html">Redef State</a></li>
<li><a class="buttons" href="interactions.html">Side Effects</a></li>
<li><a class="buttons" href="freeze-time.html">Freeze Time</a></li>
<li><a class="buttons" href="env-tweaks.html">ENV Tweaks</a></li>
<li><a class="buttons" href="emacs-tweaks.html">emacs Tweaks</a></li>
<li><a class="buttons" href="clojure-test.html">clojure.test</a></li>
<li><a class="buttons github" href="https://github.com/clojure-expectations/expectations">View On GitHub</a></li>
</ul>
<p class="header">This project is maintained by <a class="header name" href="https://github.com/seancorfield">seancorfield</a> and <a class="header name" href="https://github.com/jaycfields">jaycfields</a></p>
</header>
<section>
<h1>
<a name="expectations" class="anchor" href="#expectations"><span class="octicon octicon-link"></span></a>expectations</h1>
<blockquote>
<p>adding signal, removing noise</p>
</blockquote>
<h2>
<a name="installing" class="anchor" href="#installing"><span class="octicon octicon-link"></span></a>Installing</h2>
<p>The easiest way to use expectations in your own projects is via
<a href="http://leiningen.org">Leiningen</a> or
<a href="http://boot-clj.com">Boot</a>. Add the
following dependency to your <code>project.clj</code> or <code>build.boot</code> file:</p>
<div class="highlight"><pre><span class="p">[</span><span class="nv">expectations</span> <span class="s">"2.1.10"</span><span class="p">]</span>
</pre></div>
<p>note: expectations can go in a <code class="highlight k">:dev</code> profile in <code>project.clj</code>,
or have <code class="highlight"><span class="ss">:scope</span> <span class="s">"test"</span></code> in <code>build.boot</code>,
to avoid pushing the dependency downstream.</p>
<p>To build expectations from source, use <a href="http://leiningen.org">Leiningen</a> and run the following commands:</p>
<div class="highlight"><pre><span class="nv">$ </span>lein clean
<span class="nv">$ </span>lein javac
<span class="nv">$ </span>lein jar
</pre></div>
<h2>
<a name="getting-started-with-leiningen" class="anchor" href="#getting-started-with-leiningen"><span class="octicon octicon-link"></span></a>Getting Started With Leiningen</h2>
<p>Add <code>simple_test.clj</code> to your test directory</p>
<div class="highlight"><pre><span class="p">(</span><span class="kd">ns </span><span class="nv">simple-test</span>
<span class="p">(</span><span class="ss">:require</span> <span class="p">[</span><span class="nv">expectations</span> <span class="ss">:refer :all</span><span class="p">)])</span>
<span class="p">(</span><span class="nf">expect</span> <span class="nb">nil? </span><span class="nv">nil</span><span class="p">)</span>
</pre></div>
<p>expectations integrates with Leiningen via <a href="https://github.com/clojure-expectations/lein-expectations">lein-expectations</a>.</p>
<h3>
<a name="usage-for-lein-expectations" class="anchor" href="#usage-for-lein-expectations"><span class="octicon octicon-link"></span></a>Usage for lein-expectations:</h3>
<p>Declare <code>lein-expectations</code> in <code>project.clj</code>:</p>
<div class="highlight"><pre><span class="ss">:plugins</span> <span class="p">[[</span><span class="nv">lein-expectations</span> <span class="s">"0.0.8"</span><span class="p">]]</span>
</pre></div>
<p>To run all your tests:</p>
<div class="highlight"><pre><span class="nv">$ </span>lein expectations
</pre></div>
<p>You can also use <a href="https://github.com/clojure-expectations/lein-autoexpect">lein-autoexpect</a> to automatically run expectations when your Clojure source changes.</p>
<h2>
<a name="getting-started-with-boot" class="anchor" href="#getting-started-with-boot"><span class="octicon octicon-link"></span></a>Getting Started With Boot</h2>
<p>Add <code>simple_test.clj</code> to your test directory</p>
<div class="highlight"><pre><span class="p">(</span><span class="kd">ns </span><span class="nv">simple-test</span>
<span class="p">(</span><span class="ss">:require</span> <span class="p">[</span><span class="nv">expectations</span> <span class="ss">:require :all</span><span class="p">)])</span>
<span class="p">(</span><span class="nf">expect</span> <span class="nb">nil? </span><span class="nv">nil</span><span class="p">)</span>
</pre></div>
<p>expectations integrates with Boot via <a href="https://github.com/seancorfield/boot-expectations">boot-expectations</a>.</p>
<h3>
<a name="usage-for-boot-expectations" class="anchor" href="#usage-for-boot-expectations"><span class="octicon octicon-link"></span></a>Usage for boot-expectations:</h3>
<p>Declare <code>boot-expectations</code> in <code>build.boot</code>:</p>
<div class="highlight"><pre><span class="p">(</span><span class="nf">merge-env!</span> <span class="ss">:dependencies</span>
<span class="p">'[[</span><span class="nv">seancorfield/boot-expectations</span> <span class="s">"1.0.11"</span> <span class="ss">:scope</span> <span class="s">"test"</span><span class="p">]])</span>
<span class="p">(</span><span class="kd">require</span> <span class="p">'[</span><span class="nv">seancorfield.boot-expectations</span> <span class="ss">:refer</span> <span class="p">[</span><span class="nv">expectations</span><span class="p">]])</span>
</pre></div>
<p>To run all your tests:</p>
<div class="highlight"><pre><span class="nv">$ </span>boot expectations
</pre></div>
<p>You can also use <code>boot watch expectations</code> to automatically run expectations when your Clojure source changes.</p>
<h2>
<a name="getting-started-with-emacs" class="anchor" href="#getting-started-with-emacs"><span class="octicon octicon-link"></span></a>Getting Started With Emacs</h2>
<p>Add simple_test.clj to your test directory</p>
<div class="highlight"><pre><span class="p">(</span><span class="kd">ns </span><span class="nv">simple-test</span>
<span class="p">(</span><span class="ss">:require</span> <span class="p">[</span><span class="nv">expectations</span> <span class="ss">:require :all</span><span class="p">)])</span>
<span class="p">(</span><span class="nf">expect</span> <span class="nb">nil? </span><span class="nv">nil</span><span class="p">)</span>
</pre></div>
<p>Follow the directions available on <a href="https://github.com/clojure-expectations/expectations-mode">expectations-mode</a></p>
<h2>
<a name="getting-started-with-intellij" class="anchor" href="#getting-started-with-intellij"><span class="octicon octicon-link"></span></a>Getting Started With IntelliJ</h2>
<p>Create a directory and mark it as a Test Source. <a href="http://www.jetbrains.com/idea/webhelp/configuring-folders-within-a-content-root.html#mark">more info</a>
For example, you can create proj/test/java and mark 'java' as a test source. Then you also create proj/test/clojure and also mark that as a test source directory.</p>
<p>If you want all of your tests to run in JUnit all you need to do is implement ExpectationsTestRunner.TestSource.
The following example is what I use to run all the tests in expectations with JUnit.</p>
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">expectations.junit.ExpectationsTestRunner</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.junit.runner.RunWith</span><span class="o">;</span>
<span class="nd">@RunWith</span><span class="o">(</span><span class="n">expectations</span><span class="o">.</span><span class="na">junit</span><span class="o">.</span><span class="na">ExpectationsTestRunner</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">ClojureTests</span> <span class="kd">implements</span> <span class="n">ExpectationsTestRunner</span><span class="o">.</span><span class="na">TestSource</span><span class="o">{</span>
<span class="kd">public</span> <span class="n">String</span> <span class="nf">testPath</span><span class="o">()</span> <span class="o">{</span>
<span class="c1">// return the path to your root test dir here</span>
<span class="k">return</span> <span class="s">"test/root/dir"</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
</pre></div>
<p>Create ClojureTests.java in your proj/test/java directory. Next you can create sample-test in proj/test/clojure.</p>
<div class="highlight"><pre><span class="p">(</span><span class="kd">ns </span><span class="nv">simple-test</span>
<span class="p">(</span><span class="ss">:require</span> <span class="p">[</span><span class="nv">expectations</span> <span class="ss">:require :all</span><span class="p">)])</span>
<span class="p">(</span><span class="nf">expect</span> <span class="nb">nil? </span><span class="nv">nil</span><span class="p">)</span>
</pre></div>
<p>That's it, you can now use the JUnit Test Runner built into IntelliJ to execute your expectations.</p>
<h2>
<a name="getting-started-otherwise" class="anchor" href="#getting-started-otherwise"><span class="octicon octicon-link"></span></a>Getting Started Otherwise</h2>
<p>By default the tests run on JVM shutdown, so all you need to do is run your clj file and you should see the expectations output.</p>
<p>You can test that everything is working correctly by using
expectations in a simple test.</p>
<div class="highlight"><pre><span class="p">(</span><span class="kd">ns </span><span class="nv">simple.test</span>
<span class="p">(</span><span class="ss">:require</span> <span class="p">[</span><span class="nv">expectations</span> <span class="ss">:require :all</span><span class="p">)])</span>
<span class="p">(</span><span class="nf">expect</span> <span class="nb">nil? </span><span class="nv">nil</span><span class="p">)</span>
</pre></div>
<p>(assuming you've put your dependencies in a (relatively pathed) lib dir)</p>
<p>Running your clj should be similar to:</p>
<div class="highlight"><pre><span class="nv">$ </span>java -cp <span class="s2">"lib/*"</span> clojure.main -i /path/to/your/simple/test.clj
</pre></div>
<p>At this point you should see output similar to:</p>
<pre>Ran 1 tests containing 1 assertions in 5 msecs
0 failures, 0 errors.</pre>
<p>You can run the examples in expectations with:</p>
<div class="highlight"><pre><span class="nv">$ </span>java -cp <span class="s2">"lib/*"</span> clojure.main -i /path/to/expectations/test/clojure/success/success_examples.clj
</pre></div>
</section>
<footer>
<p><small>Hosted on <a href="https://pages.github.com">GitHub Pages</a> using the Dinky theme</small></p>
</footer>
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
</body>
</html>