| Class | Uttk::Strategies::RUnit |
| In: |
lib/uttk/strategies/RUnit.rb
|
| Parent: | Strategy |
This strategy is wrapper around a Ruby unit test suite based on the test/unit library. Using RUnit you avoid the Ruby `require’ problem and you use all the power of the Uttk‘s Suite and/or Pool.
RUnit works by invoking Ruby on the specified file and then by parsing the output in order to inject it into the Uttk‘s log stream. To do that, you must use a specific TestRunner based on YAML. This TestRunner produces a YAML output readable by a human and the strategy.
You need to first write your unit test suite using the test/unit package and the YAML TestRunner. Then, you write a few line in the input Uttk file to incorporate the unit test in the Uttk‘s suite.
require 'foo'
class FooTest < Test::Unit::TestCase
def test_1
assert(true)
end
end
---
RUnit example test:
strategy: RUnit
input: !path my_unit_directory/foo_test.rb
If you find cumbersome to write for every unit test files a single RUnit strategy into the YAML input file of Uttk, there is another way that is used in test/unit-suite.yml.
# File lib/uttk/strategies/RUnit.rb, line 116 def abort_hook @runner.abort @data if @runner and defined? @data super end
# File lib/uttk/strategies/RUnit.rb, line 83 def assertion matcher_result = command_matcher[UM::StreamMatcher, {:error => ''}, @data] @log << matcher_result raise_error('Error output not empty') if matcher_result.failure? if @data.output.zero? skip('No result has been collected probably because no test ' + 'suite has been run') end output = YAML.load @data.output.read @log[:result] = output o = OpenStruct.new output if o.tests_number.zero? skip_pass 'No test suite in this file' end pass if o.failures_number.zero? and o.errors_number.zero? rpath = '/^failures$/^default_test/No tests were specified' if o.failures_number == 1 and output.rpath_find :first, rpath skip 'No tests were specified' elsif o.failures_number.zero? fail 'There are errors' elsif o.errors_number.zero? fail 'There are failures' end fail 'There are failures and errors' end
# File lib/uttk/strategies/RUnit.rb, line 61 def prologue super @runner = mk_system_runner @command = '<<ruby>>'.to_ocmd << '--' << '<<uttk-unit>>' if @verbose @command << '--verbose' else @command << '--no-verbose' end @load_path.each { |x| @command << '-I' << x } @requires.to_ocmd_args.each { |x| @command << '-r' << x } @command += @uttk_unit_options.to_ocmd_args @command << '--' << @input << '--' << '--runner' << 'yaml' @command.dir = @dir end