Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 286 lines (214 sloc) 7.635 kb
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored
1 = minitest/{unit,spec,mock,benchmark}
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
2
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored
3 home :: https://github.com/seattlerb/minitest
36d0657 @zenspider prepped for release
zenspider authored
4 rdoc :: http://docs.seattlerb.org/minitest
8704fe6 @zenspider + Added link to vim bundle. (sunaku)
zenspider authored
5 vim :: https://github.com/sunaku/vim-ruby-minitest
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
6
7 == DESCRIPTION:
8
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
9 minitest provides a complete suite of testing facilities supporting
10 TDD, BDD, mocking, and benchmarking.
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
11
62e882c @zenspider Added some choice quotes to the readme
zenspider authored
12 "I had a class with Jim Weirich on testing last week and we were
13 allowed to choose our testing frameworks. Kirk Haines and I were
14 paired up and we cracked open the code for a few test
15 frameworks...
16
17 I MUST say that mintiest is *very* readable / understandable
18 compared to the 'other two' options we looked at. Nicely done and
19 thank you for helping us keep our mental sanity."
20
21 -- Wayne E. Seguin
22
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
23 minitest/unit is a small and incredibly fast unit testing framework.
24 It provides a rich set of assertions to make your tests clean and
25 readable.
26
27 minitest/spec is a functionally complete spec engine. It hooks onto
28 minitest/unit and seamlessly bridges test assertions over to spec
29 expectations.
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
30
772913b @zenspider Updated doco
zenspider authored
31 minitest/benchmark is an awesome way to assert the performance of your
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
32 algorithms in a repeatable manner. Now you can assert that your newb
33 co-worker doesn't replace your linear algorithm with an exponential
34 one!
35
36 minitest/mock by Steven Baker, is a beautifully tiny mock object
37 framework.
772913b @zenspider Updated doco
zenspider authored
38
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
39 minitest/pride shows pride in testing and adds coloring to your test
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored
40 output. I guess it is an example of how to write IO pipes too. :P
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
41
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
42 minitest/unit is meant to have a clean implementation for language
43 implementors that need a minimal set of methods to bootstrap a working
44 test suite. For example, there is no magic involved for test-case
45 discovery.
b8f07dd @zenspider Updated history and readme for release
zenspider authored
46
62e882c @zenspider Added some choice quotes to the readme
zenspider authored
47 "Again, I can’t praise enough the idea of a testing/specing
48 framework that I can actually read in full in one sitting!"
49
50 -- Piotr Szotkowski
51
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
52 == FEATURES/PROBLEMS:
53
772913b @zenspider Updated doco
zenspider authored
54 * minitest/autorun - the easy and explicit way to run all your tests.
ea1ef6f @zenspider more readme enhancements
zenspider authored
55 * minitest/unit - a very fast, simple, and clean test system.
56 * minitest/spec - a very fast, simple, and clean spec system.
57 * minitest/mock - a simple and clean mock system.
58 * minitest/benchmark - an awesome way to assert your algorithm's performance.
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
59 * minitest/pride - show your pride in testing!
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
60 * Incredibly small and fast runner, but no bells and whistles.
61
c1fcbe0 @zenspider Added clarification doco
zenspider authored
62 == RATIONALE:
63
64 See design_rationale.rb to see how specs and tests work in minitest.
65
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
66 == SYNOPSIS:
67
68 Given that you'd like to test the following class:
69
772913b @zenspider Updated doco
zenspider authored
70 class Meme
71 def i_can_has_cheezburger?
72 "OHAI!"
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
73 end
74
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored
75 def will_it_blend?
772913b @zenspider Updated doco
zenspider authored
76 "YES!"
77 end
78 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
79
80 === Unit tests
81
fe4dac2 @zenspider more rdoc improvements via tenderlove
zenspider authored
82 require 'minitest/autorun'
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
83
772913b @zenspider Updated doco
zenspider authored
84 class TestMeme < MiniTest::Unit::TestCase
85 def setup
86 @meme = Meme.new
87 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
88
772913b @zenspider Updated doco
zenspider authored
89 def test_that_kitty_can_eat
90 assert_equal "OHAI!", @meme.i_can_has_cheezburger?
91 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
92
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored
93 def test_that_it_will_not_blend
94 refute_match /^no/i, @meme.will_it_blend?
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
95 end
772913b @zenspider Updated doco
zenspider authored
96 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
97
98 === Specs
99
fe4dac2 @zenspider more rdoc improvements via tenderlove
zenspider authored
100 require 'minitest/autorun'
772913b @zenspider Updated doco
zenspider authored
101
102 describe Meme do
103 before do
104 @meme = Meme.new
105 end
106
107 describe "when asked about cheeseburgers" do
ea1ef6f @zenspider more readme enhancements
zenspider authored
108 it "must respond positively" do
772913b @zenspider Updated doco
zenspider authored
109 @meme.i_can_has_cheezburger?.must_equal "OHAI!"
110 end
111 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
112
772913b @zenspider Updated doco
zenspider authored
113 describe "when asked about blending possibilities" do
114 it "won't say no" do
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored
115 @meme.will_it_blend?.wont_match /^no/i
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
116 end
772913b @zenspider Updated doco
zenspider authored
117 end
118 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
119
772913b @zenspider Updated doco
zenspider authored
120 === Benchmarks
121
122 Add benchmarks to your regular unit tests. If the unit tests fail, the
123 benchmarks won't run.
124
125 # optionally run benchmarks, good for CI-only work!
126 require 'minitest/benchmark' if ENV["BENCH"]
127
128 class TestMeme < MiniTest::Unit::TestCase
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
129 # Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
772913b @zenspider Updated doco
zenspider authored
130 def bench_my_algorithm
0a2bfcc @zenspider + Improved readme based on feedback from others
zenspider authored
131 assert_performance_linear 0.9999 do |n| # n is a range value
5bf6342 @zenspider - Clarified the documentation of minitest/benchmark (eregon)
zenspider authored
132 @obj.my_algorithm(n)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
133 end
772913b @zenspider Updated doco
zenspider authored
134 end
135 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
136
772913b @zenspider Updated doco
zenspider authored
137 Or add them to your specs. If you make benchmarks optional, you'll
138 need to wrap your benchmarks in a conditional since the methods won't
139 be defined.
140
141 describe Meme do
142 if ENV["BENCH"] then
143 bench_performance_linear "my_algorithm", 0.9999 do |n|
144 100.times do
145 @obj.my_algorithm(n)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
146 end
147 end
148 end
772913b @zenspider Updated doco
zenspider authored
149 end
150
151 outputs something like:
152
153 # Running benchmarks:
154
155 TestBlah 100 1000 10000
156 bench_my_algorithm 0.006167 0.079279 0.786993
157 bench_other_algorithm 0.061679 0.792797 7.869932
158
159 Output is tab-delimited to make it easy to paste into a spreadsheet.
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
160
161 === Mocks
162
772913b @zenspider Updated doco
zenspider authored
163 class MemeAsker
164 def initialize(meme)
165 @meme = meme
166 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
167
772913b @zenspider Updated doco
zenspider authored
168 def ask(question)
169 method = question.tr(" ","_") + "?"
170 @meme.send(method)
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
171 end
772913b @zenspider Updated doco
zenspider authored
172 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
173
772913b @zenspider Updated doco
zenspider authored
174 require 'minitest/autorun'
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
175
772913b @zenspider Updated doco
zenspider authored
176 describe MemeAsker do
177 before do
178 @meme = MiniTest::Mock.new
179 @meme_asker = MemeAsker.new @meme
180 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
181
772913b @zenspider Updated doco
zenspider authored
182 describe "#ask" do
183 describe "when passed an unpunctuated question" do
184 it "should invoke the appropriate predicate method on the meme" do
8761009 @zenspider Got the meme right -- "*Will* it blend?" not "Does it blend?" -- shee…
zenspider authored
185 @meme.expect :will_it_blend?, :return_value
186 @meme_asker.ask "will it blend"
772913b @zenspider Updated doco
zenspider authored
187 @meme.verify
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
188 end
189 end
190 end
772913b @zenspider Updated doco
zenspider authored
191 end
659f105 @zenspider + Added examples to readme (Mike Dalessio)
zenspider authored
192
6023c87 @zenspider + MiniTest::Unit.runner=(runner) provides an easy way of creating cus…
zenspider authored
193 === Customizable Test Runner Types:
194
195 MiniTest::Unit.runner=(runner) provides an easy way of creating custom
196 test runners for specialized needs. Justin Weiss provides the
197 following real-world example to create an alternative to regular
198 fixture loading:
199
200 class MiniTestWithHooks::Unit < MiniTest::Unit
201 def before_suites
202 end
203
204 def after_suites
205 end
206
207 def _run_suites(suites, type)
208 begin
209 before_suites
210 super(suites, type)
211 ensure
212 after_suites
213 end
214 end
215
216 def _run_suite(suite, type)
217 begin
218 suite.before_suite
219 super(suite, type)
220 ensure
221 suite.after_suite
222 end
223 end
224 end
225
226 module MiniTestWithTransactions
227 class Unit < MiniTestWithHooks::Unit
228 include TestSetupHelper
229
230 def before_suites
231 super
232 setup_nested_transactions
233 # load any data we want available for all tests
234 end
235
236 def after_suites
237 teardown_nested_transactions
238 super
239 end
240 end
241 end
242
243 MiniTest::Unit.runner = MiniTestWithTransactions::Unit.new
244
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
245 == REQUIREMENTS:
246
772913b @zenspider Updated doco
zenspider authored
247 * Ruby 1.8, maybe even 1.6 or lower. No magic is involved.
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
248
249 == INSTALL:
250
ea1ef6f @zenspider more readme enhancements
zenspider authored
251 sudo gem install minitest
252
772913b @zenspider Updated doco
zenspider authored
253 On 1.9, you already have it. To get newer candy you can still install
ea1ef6f @zenspider more readme enhancements
zenspider authored
254 the gem, but you'll need to activate the gem explicitly to use it:
772913b @zenspider Updated doco
zenspider authored
255
ea1ef6f @zenspider more readme enhancements
zenspider authored
256 require 'rubygems'
257 gem 'minitest' # ensures you're using the gem, and not the built in MT
258 require 'minitest/autorun'
259
260 # ... usual testing stuffs ...
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
261
262 == LICENSE:
263
264 (The MIT License)
265
7516317 @zenspider Updated url section, switched to github for repo/home url, and cleane…
zenspider authored
266 Copyright (c) Ryan Davis, seattle.rb
07a4672 @zenspider Branched miniunit into minitest w/o test/unit compatibility
zenspider authored
267
268 Permission is hereby granted, free of charge, to any person obtaining
269 a copy of this software and associated documentation files (the
270 'Software'), to deal in the Software without restriction, including
271 without limitation the rights to use, copy, modify, merge, publish,
272 distribute, sublicense, and/or sell copies of the Software, and to
273 permit persons to whom the Software is furnished to do so, subject to
274 the following conditions:
275
276 The above copyright notice and this permission notice shall be
277 included in all copies or substantial portions of the Software.
278
279 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
280 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
281 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
282 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
283 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
284 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
285 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.