I have assertions in place in my ruby script.
Each of these assertions also has a message to describe the assertion.
So I have two questions revolving around this
I want the messages associated with each assert to display as the test progresses. Currently the Message only displays when any thing fails
The entire test exits when any assertion fails. How do i make the tests continue even if one assertion fails?
Sample code that i am using
assert_match("hey", "hey this is a test", "The word exists in the string")
So the output currently looks like -
ruby ruby11.rb -v v
Loaded suite ruby
Started
test_ruby(Ruby):
F
Finished in 40.555587 seconds.
1) Failure:
test_ruby11(Ruby11) [ruby11.rb:73]:
Text box not displayed
<false> is not true.
1 tests, 3 assertions, 1 failures, 0 errors
And i want it to look like
ruby ruby.rb -v v
Loaded suite ruby
Started
test_ruby(Ruby):
F
ok 1 - First test successful
ok 2 - The text is displayed
ok 3 - The image is present
not ok 4 - Text box not displayed
ok - The picture is visible
Finished in 40.555587 seconds.
1) Failure:
test_ruby(Ruby) [ruby11.rb:73]:
Text box not displayed
<false> is not true.
1 tests, 4 assertions, 1 failures, 0 errors
So in the above desired display, all assertion states are displayed as an when the test is executed. (Something like TAP in perl). I am new to ruby, so i am sure there is something basic I am doing wrong.
Also i have tried the verbose parameter ruby ruby.rb -v v
, while running the script. But that does not help either.
Help will be apprecaited
This is just how I do it, but consider the following:
test_text_appears
andtest_image_appears
tests. Having one assertion per test means that when something does break, you can see all of the assertions that fail, rather than just the first assertion in a test with lots of assertions.test_text_appears
.There isn't much choice for TAP output specifically. One test framework that did was Bacon, which was an RSpec clone with TAP output, but it doesn't appear to be active anymore.
If what you want is compatibility with Continuous Integration, The ci_reporter gem can be used to convert test results (from both Test::Unit and RSpec) to the JUnit XML format which will make it work with Jenkins/Hudson, Bamboo, and other JUnit-aware CI servers.
But unlike RSpec, Test/Unit has a limitation where it doesn't report the tests that pass. There's a discussion about running Test/Unit through the RSpec HTML formatter which will include the names of the passing tests here.
2015 update: You may want to look into MiniTest, which is gaining popularity now and has many formatter plugins and is otherwise very flexible/extendable.