Class: Bozo::TestRunners::Nunit
- Inherits:
-
Object
- Object
- Bozo::TestRunners::Nunit
- Defined in:
- lib/bozo/test_runners/nunit.rb
Overview
A TestRunner for NUnit By default the x64 runner is used. If you want to use a different platform runner then set the platform, e.g. ‘x86’.
Dotcover integration
To enable integration with the dotcover test runner the following interface needs to be used
runner_path # should return the path to the runners executable
runner_args # should return the arguments to be passed to use
Instance Method Summary collapse
- #coverage(coverage) ⇒ Object
- #destination(destination) ⇒ Object
- #exclude(exclude) ⇒ Object
- #execute ⇒ Object
- #execute_in_parallel ⇒ Object
- #include(include) ⇒ Object
-
#initialize ⇒ Nunit
constructor
A new instance of Nunit.
- #platform(platform) ⇒ Object
- #project(path) ⇒ Object
- #report_path(path) ⇒ Object
-
#runner_args(projects = nil, report_prefix = nil) ⇒ Object
Returns the arguments required for the runner’s executable.
-
#runner_path ⇒ Object
Returns the path to the runner’s executable.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Nunit
Returns a new instance of Nunit.
15 16 17 18 19 20 |
# File 'lib/bozo/test_runners/nunit.rb', line 15 def initialize @projects = [] @include = [] @exclude = [] @execute_in_parallel = false end |
Instance Method Details
#coverage(coverage) ⇒ Object
38 39 40 |
# File 'lib/bozo/test_runners/nunit.rb', line 38 def coverage(coverage) @coverage = coverage end |
#destination(destination) ⇒ Object
22 23 24 |
# File 'lib/bozo/test_runners/nunit.rb', line 22 def destination(destination) @destination = destination end |
#exclude(exclude) ⇒ Object
47 48 49 50 |
# File 'lib/bozo/test_runners/nunit.rb', line 47 def exclude(exclude) cannot_define_both_include_and_exclude_categories if @include.any? @exclude << exclude end |
#execute ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/bozo/test_runners/nunit.rb', line 111 def execute if @execute_in_parallel failed_projects = Queue.new threads = [] @projects.each do |project| t = Thread.new { begin execute_command :nunit, [runner_path] << runner_args([project], "#{project}-#{Time.now.to_i}") rescue failed_projects.push(project) end } threads.push(t) end threads.each(&:join) failed = [] until failed_projects.empty? failed << failed_projects.pop end if failed.length > 0 raise Bozo::ExecutionError.new(:nunit, [runner_path] << failed, 1) end else execute_command :nunit, [runner_path] << runner_args end end |
#execute_in_parallel ⇒ Object
52 53 54 |
# File 'lib/bozo/test_runners/nunit.rb', line 52 def execute_in_parallel @execute_in_parallel = true end |
#include(include) ⇒ Object
42 43 44 45 |
# File 'lib/bozo/test_runners/nunit.rb', line 42 def include(include) cannot_define_both_include_and_exclude_categories if @exclude.any? @include << include end |
#platform(platform) ⇒ Object
26 27 28 |
# File 'lib/bozo/test_runners/nunit.rb', line 26 def platform(platform) @platform = platform end |
#project(path) ⇒ Object
30 31 32 |
# File 'lib/bozo/test_runners/nunit.rb', line 30 def project(path) @projects << path end |
#report_path(path) ⇒ Object
34 35 36 |
# File 'lib/bozo/test_runners/nunit.rb', line 34 def report_path(path) @report_path = path end |
#runner_args(projects = nil, report_prefix = nil) ⇒ Object
Returns the arguments required for the runner’s executable.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/bozo/test_runners/nunit.rb', line 85 def runner_args(projects = nil, report_prefix = nil) projects = @projects if projects.nil? report_prefix = Time.now.to_i if report_prefix.nil? args = [] projects.each do |project| ('temp', 'msbuild', project, '**', "#{project}.dll").each do |test_dll| args << "\"#{test_dll}\"" end end args << '/nologo' report_path = @report_path report_path = ('temp', 'nunit', "#{report_prefix}-nunit-report.xml") unless report_path # Ensure the directory is there because NUnit won't make it FileUtils.mkdir_p File.dirname(report_path) args << "/xml:\"#{report_path}\"" args << "/include:#{@include.join(',')}" if @include.any? args << "/exclude:#{@exclude.join(',')}" if @exclude.any? args end |
#runner_path ⇒ Object
Returns the path to the runner’s executable.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bozo/test_runners/nunit.rb', line 63 def runner_path exe_name = "nunit-console.exe" if defined? @platform log_debug "Looking for runner with #@platform platform" exe_name = "nunit-console-#@platform.exe" end nunit_runners = ('packages', 'NUnit*', 'tools', exe_name) raise nunit_runner_not_found if nunit_runners.empty? raise multiple_runners_found if nunit_runners.size > 1 nunit_runner = nunit_runners.first log_debug "Found runner at #{nunit_runner}" nunit_runner end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/bozo/test_runners/nunit.rb', line 56 def to_s "Run tests with nunit against projects #{@projects}" end |