= minitest/{unit,spec,mock,benchmark}
home :: https://github.com/seattlerb/minitest
rdoc :: http://docs.seattlerb.org/minitest
vim :: https://github.com/sunaku/vim-ruby-minitest
== DESCRIPTION:
minitest provides a complete suite of testing facilities supporting
TDD, BDD, mocking, and benchmarking.
"I had a class with Jim Weirich on testing last week and we were
allowed to choose our testing frameworks. Kirk Haines and I were
paired up and we cracked open the code for a few test
frameworks...
I MUST say that minitest is *very* readable / understandable
compared to the 'other two' options we looked at. Nicely done and
thank you for helping us keep our mental sanity."
-- Wayne E. Seguin
minitest/unit is a small and incredibly fast unit testing framework.
It provides a rich set of assertions to make your tests clean and
readable.
minitest/spec is a functionally complete spec engine. It hooks onto
minitest/unit and seamlessly bridges test assertions over to spec
expectations.
minitest/benchmark is an awesome way to assert the performance of your
algorithms in a repeatable manner. Now you can assert that your newb
co-worker doesn't replace your linear algorithm with an exponential
one!
minitest/mock by Steven Baker, is a beautifully tiny mock (and stub)
object framework.
minitest/pride shows pride in testing and adds coloring to your test
output. I guess it is an example of how to write IO pipes too. :P
minitest/unit is meant to have a clean implementation for language
implementors that need a minimal set of methods to bootstrap a working
test suite. For example, there is no magic involved for test-case
discovery.
"Again, I can't praise enough the idea of a testing/specing
framework that I can actually read in full in one sitting!"
-- Piotr Szotkowski
Comparing to rspec:
rspec is a testing DSL. minitest is ruby.
-- Adam Hawkins, "Bow Before MiniTest"
minitest doesn't reinvent anything that ruby already provides, like:
classes, modules, inheritance, methods. This means you only have to
learn ruby to use minitest and all of your regular OO practices like
extract-method refactorings still apply.
== FEATURES/PROBLEMS:
* minitest/autorun - the easy and explicit way to run all your tests.
* minitest/unit - a very fast, simple, and clean test system.
* minitest/spec - a very fast, simple, and clean spec system.
* minitest/mock - a simple and clean mock/stub system.
* minitest/benchmark - an awesome way to assert your algorithm's performance.
* minitest/pride - show your pride in testing!
* Incredibly small and fast runner, but no bells and whistles.
== RATIONALE:
See design_rationale.rb to see how specs and tests work in minitest.
== SYNOPSIS:
Given that you'd like to test the following class:
class Meme
def i_can_has_cheezburger?
"OHAI!"
end
def will_it_blend?
"YES!"
end
end
=== Unit tests
require 'minitest/autorun'
class TestMeme < MiniTest::Unit::TestCase
def setup
@meme = Meme.new
end
def test_that_kitty_can_eat
assert_equal "OHAI!", @meme.i_can_has_cheezburger?
end
def test_that_it_will_not_blend
refute_match /^no/i, @meme.will_it_blend?
end
def test_that_will_be_skipped
skip "test this later"
end
end
=== Specs
require 'minitest/autorun'
describe Meme do
before do
@meme = Meme.new
end
describe "when asked about cheeseburgers" do
it "must respond positively" do
@meme.i_can_has_cheezburger?.must_equal "OHAI!"
end
end
describe "when asked about blending possibilities" do
it "won't say no" do
@meme.will_it_blend?.wont_match /^no/i
end
end
end
For matchers support check out:
https://github.com/zenspider/minitest-matchers
=== Benchmarks
Add benchmarks to your regular unit tests. If the unit tests fail, the
benchmarks won't run.
# optionally run benchmarks, good for CI-only work!
require 'minitest/benchmark' if ENV["BENCH"]
class TestMeme < MiniTest::Unit::TestCase
# Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
def bench_my_algorithm
assert_performance_linear 0.9999 do |n| # n is a range value
@obj.my_algorithm(n)
end
end
end
Or add them to your specs. If you make benchmarks optional, you'll
need to wrap your benchmarks in a conditional since the methods won't
be defined.
describe Meme do
if ENV["BENCH"] then
bench_performance_linear "my_algorithm", 0.9999 do |n|
100.times do
@obj.my_algorithm(n)
end
end
end
end
outputs something like:
# Running benchmarks:
TestBlah 100 1000 10000
bench_my_algorithm 0.006167 0.079279 0.786993
bench_other_algorithm 0.061679 0.792797 7.869932
Output is tab-delimited to make it easy to paste into a spreadsheet.
=== Mocks
class MemeAsker
def initialize(meme)
@meme = meme
end
def ask(question)
method = question.tr(" ","_") + "?"
@meme.__send__(method)
end
end
require 'minitest/autorun'
describe MemeAsker do
before do
@meme = MiniTest::Mock.new
@meme_asker = MemeAsker.new @meme
end
describe "#ask" do
describe "when passed an unpunctuated question" do
it "should invoke the appropriate predicate method on the meme" do
@meme.expect :will_it_blend?, :return_value
@meme_asker.ask "will it blend"
@meme.verify
end
end
end
end
=== Stubs
def test_stale_eh
obj_under_test = Something.new
refute obj_under_test.stale?
Time.stub :now, Time.at(0) do # stub goes away once the block is done
assert obj_under_test.stale?
end
end
A note on stubbing: In order to stub a method, the method must
actually exist prior to stubbing. Use a singleton method to create a
new non-existing method:
def obj_under_test.fake_method
...
end
=== Customizable Test Runner Types:
MiniTest::Unit.runner=(runner) provides an easy way of creating custom
test runners for specialized needs. Justin Weiss provides the
following real-world example to create an alternative to regular
fixture loading:
class MiniTestWithHooks::Unit < MiniTest::Unit
def before_suites
end
def after_suites
end
def _run_suites(suites, type)
begin
before_suites
super(suites, type)
ensure
after_suites
end
end
def _run_suite(suite, type)
begin
suite.before_suite
super(suite, type)
ensure
suite.after_suite
end
end
end
module MiniTestWithTransactions
class Unit < MiniTestWithHooks::Unit
include TestSetupHelper
def before_suites
super
setup_nested_transactions
# load any data we want available for all tests
end
def after_suites
teardown_nested_transactions
super
end
end
end
MiniTest::Unit.runner = MiniTestWithTransactions::Unit.new
== FAQ
=== How to test SimpleDelegates?
The following implementation and test:
class Worker < SimpleDelegator
def work
end
end
describe Worker do
before do
@worker = Worker.new(Object.new)
end
it "must respond to work" do
@worker.must_respond_to :work
end
end
outputs a failure:
1) Failure:
Worker#test_0001_must respond to work [bug11.rb:16]:
Expected #<Object:0x007f9e7184f0a0> (Object) to respond to #work.
Worker is a SimpleDelegate which in 1.9+ is a subclass of BasicObject.
Expectations are put on Object (one level down) so the Worker
(SimpleDelegate) hits `method_missing` and delegates down to the
`Object.new` instance. That object doesn't respond to work so the test
fails.
You can bypass `SimpleDelegate#method_missing` by extending the worker
with `MiniTest::Expectations`. You can either do that in your set
没有合适的资源?快使用搜索试试~ 我知道了~
ruby-2.4.2.tar.gz
需积分: 9 24 下载量 106 浏览量
2017-11-27
14:03:27
上传
评论 1
收藏 13.53MB GZ 举报
温馨提示
共4032个文件
rb:2395个
c:593个
h:190个
Ruby,一种简单快捷的面向对象(面向对象程序设计)脚本语言,在20世纪90年代由日本人松本行弘(Yukihiro Matsumoto)开发,遵守GPL协议和Ruby License。它的灵感与特性来自于 Perl、Smalltalk、Eiffel、Ada以及 Lisp 语言。
资源推荐
资源详情
资源评论
收起资源包目录
ruby-2.4.2.tar.gz (4032个子文件)
ChangeLog-2.0.0 830KB
ChangeLog-1.8.0 728KB
ChangeLog-2.1.0 604KB
ChangeLog-2.2.0 401KB
ChangeLog-2.3.0 401KB
ChangeLog-2.4.0 328KB
NEWS-2.0.0 18KB
NEWS-2.3.0 13KB
NEWS-2.1.0 12KB
NEWS-2.2.0 11KB
ChangeLog.libffi-3.1 206KB
ChangeLog-0.60_to_1.1 129KB
ruby.1 19KB
NEWS-1.9.1 16KB
ri.1 4KB
rake.1 4KB
irb.1 3KB
erb.1 3KB
goruby.1 788B
NEWS-1.9.2 12KB
ChangeLog-1.9.3 2.86MB
NEWS-1.9.3 10KB
ffi_call.3 2KB
ffi_prep_cif_var.3 1KB
ffi_prep_cif.3 1KB
ffi.3 850B
ChangeLog-0.06_to_0.52 47KB
ChangeLog-0.50_to_0.60 19KB
NEWS-1.8.7 14KB
configure.ac 17KB
Makefile.am 8KB
Makefile.am 4KB
Makefile.am 249B
Makefile.am 207B
Setup.atheos 239B
.autotest 1KB
rcs.awk 649B
fib.awk 101B
wc.input.base 6KB
rb_optparse.bash 457B
configure.bat 6KB
ifchange.bat 1KB
rmdirs.bat 834B
rm.bat 380B
makedirs.bat 93B
lex.c.blt 13KB
props.h.blt 8KB
BSD-MIT 1023B
BSDL 1KB
BSDL 1KB
build-transcode 344B
bundled_gems 112B
big5.c 2.97MB
utf8_mac.c 2.7MB
japanese_euc.c 1.99MB
korean.c 1.22MB
gb18030.c 991KB
gbk.c 947KB
chinese.c 942KB
utf8tbl.c 823KB
japanese_sjis.c 767KB
emoji_iso2022_kddi.c 707KB
emoji_sjis_softbank.c 658KB
emoji_sjis_kddi.c 656KB
emoji_sjis_docomo.c 647KB
ripper.c 574KB
parse.c 567KB
single_byte.c 427KB
io.c 320KB
emoji.c 270KB
constdefs.c 264KB
string.c 254KB
gc.c 251KB
compile.c 224KB
date_core.c 216KB
process.c 214KB
dlmalloc.c 179KB
win32.c 174KB
bignum.c 172KB
nkf.c 170KB
regparse.c 161KB
array.c 156KB
regcomp.c 156KB
bigdecimal.c 151KB
file.c 146KB
transcode.c 136KB
time.c 128KB
zlib.c 125KB
thread.c 125KB
numeric.c 123KB
win32ole.c 117KB
regexec.c 115KB
hash.c 107KB
enum.c 102KB
util.c 101KB
re.c 101KB
scanner.c 96KB
object.c 90KB
vm.c 87KB
proc.c 82KB
共 4032 条
- 1
- 2
- 3
- 4
- 5
- 6
- 41
资源评论
liao9416
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功