Testing-Framework--Picard- is a project mainly written in Ruby, it's free.
require 'picard'
class DemoTest < Test::Unit::TestCase
include Picard::TestUnit
def test_simple_math
given
x = 1
y = 2
expect
x + y == 3
end
end
To start using picard you need to mix in Picard::TestUnit module into your TestUnit test case. It will add a special hook that will transform every test method in your test case. For instance, the "test_simple_math" method will be transformed into something like:
def test_simple_math
given
x = 1
y = 2
expect
assert_equal 3, (x + y), MESSAGE
end
end
Where the MESSAGE is:
You might notice a few things here:
gem 'picard'
There are some things I'm going to add in a week or two:
The only special case Picard supports right now is ==
. If you are using something like x != y
in your expect
block it will just insert a regular assert
which is bad. It's going to be much smarter than this soon.
In Spock it's possible to write data driven tests:
expect: x + y == z
where: x = [1, 10, 100] y = [2, 20, 200] z = [3, 30, 300]
Basically it will transform into something like:
expect:
1 + 2 == 3
10 + 20 == 30
100 + 200 == 300
Which is totally awesome! I'm going to add a similar feature to Picard soon.