Class: Bozo::TestRunners::Nunit

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeNunit

Returns a new instance of Nunit.



15
16
17
18
19
# File 'lib/bozo/test_runners/nunit.rb', line 15

def initialize
  @projects = []
  @include = []
  @exclude = []
end

Instance Method Details

#coverage(coverage) ⇒ Object



37
38
39
# File 'lib/bozo/test_runners/nunit.rb', line 37

def coverage(coverage)
  @coverage = coverage
end

#destination(destination) ⇒ Object



21
22
23
# File 'lib/bozo/test_runners/nunit.rb', line 21

def destination(destination)
  @destination = destination
end

#exclude(exclude) ⇒ Object



46
47
48
49
# File 'lib/bozo/test_runners/nunit.rb', line 46

def exclude(exclude)
  cannot_define_both_include_and_exclude_categories if @include.any?
  @exclude << exclude
end

#executeObject



103
104
105
# File 'lib/bozo/test_runners/nunit.rb', line 103

def execute
  execute_command :nunit, [runner_path] << runner_args
end

#include(include) ⇒ Object



41
42
43
44
# File 'lib/bozo/test_runners/nunit.rb', line 41

def include(include)
  cannot_define_both_include_and_exclude_categories if @exclude.any?
  @include << include
end

#platform(platform) ⇒ Object



25
26
27
# File 'lib/bozo/test_runners/nunit.rb', line 25

def platform(platform)
  @platform = platform
end

#project(path) ⇒ Object



29
30
31
# File 'lib/bozo/test_runners/nunit.rb', line 29

def project(path)
  @projects << path
end

#report_path(path) ⇒ Object



33
34
35
# File 'lib/bozo/test_runners/nunit.rb', line 33

def report_path(path)
  @report_path = path
end

#runner_argsObject

Returns the arguments required for the runner’s executable.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bozo/test_runners/nunit.rb', line 80

def runner_args
  args = []

  @projects.each do |project|
    expand_and_glob('temp', 'msbuild', project, '**', "#{project}.dll").each do |test_dll|
      args << "\"#{test_dll}\""
    end
  end
  args << '/nologo'

  report_path = @report_path
  report_path = expand_path('temp', 'nunit', "#{Time.now.to_i}-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_pathObject

Returns the path to the runner’s executable.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bozo/test_runners/nunit.rb', line 58

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 = expand_and_glob('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_sObject



51
52
53
# File 'lib/bozo/test_runners/nunit.rb', line 51

def to_s
  "Run tests with nunit against projects #{@projects}"
end