Class: Course::Assessment::Java::JavaProgrammingTestCaseReport::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/autoload/course/assessment/java/java_programming_test_case_report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_suite, test_case) ⇒ TestCase

Creates a new test case. This represents a <testcase> element.


59
60
61
62
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 59

def initialize(test_suite, test_case)
  @test_suite = test_suite
  @test_case = test_case
end

Instance Attribute Details

#test_suiteObject (readonly)

Returns the value of attribute test_suite


52
53
54
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 52

def test_suite
  @test_suite
end

Instance Method Details

#class_nameString

The name of the class.


67
68
69
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 67

def class_name
  @test_case['classname']
end

#durationFloat|nil

The duration for running the test case.


81
82
83
84
85
86
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 81

def duration
  @duration ||= begin
    duration = @test_case['duration-ms']
    duration ? duration.to_f / 1000 : nil
  end
end

#expectedString

The expected value from running the test expression


106
107
108
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 106

def expected
  @expected ||= ('expected')
end

#expressionString

The test expression


99
100
101
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 99

def expression
  @expression ||= ('expression')
end

#failed?Boolean

Checks if the test case has failed.


170
171
172
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 170

def failed?
  status == 'FAIL'
end

#failure_contentsString|nil

If there's a failure, return the contents of the failure tag. This contains the full traceback.


146
147
148
149
150
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 146

def failure_contents
  return nil unless failed?
  @test_case.search('exception/full-stacktrace').children[1].nil? ?
    '' : @test_case.search('exception/full-stacktrace').children[1].text
end

#failure_messageString|nil

If there's a failure, return the failure type and failure message. This encompasses both test failures and test errors

nil if no failure.


130
131
132
133
134
135
136
137
138
139
140
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 130

def failure_message
  return nil unless failed?
  # Checks if it is an assertion failure
  if @test_case.search('exception/message').any?
    failure_body = @test_case.search('exception/message').children[1].nil? ?
      '' : @test_case.search('exception/message').children[1].text
    "#{failure_type}: #{failure_body}"
  else
    failure_type
  end
end

#failure_typeString|nil

If there's a failure, return the failure type attribute.


155
156
157
158
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 155

def failure_type
  return nil unless failed?
  @test_case.search('exception')[0]['class']
end

#hintString

A hint to help the student pass the test case


113
114
115
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 113

def hint
  @hint ||= ('hint')
end

#identifierString

The identifier for this test case. This attempts to be unique, but it might not be.


91
92
93
94
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 91

def identifier
  class_name = self.class_name ? self.class_name + '/' : ''
  "#{@test_suite.identifier}/#{class_name}#{name.underscore}"
end

#messagesHash

Combines the different strings above into a hash


192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 192

def messages
  # prune empty and nil values
  # error_contents and failure_contents are only being stored and not displayed on the interface
  @messages ||= {
    'error': nil,
    'error_contents': nil,
    'hint': hint,
    'failure': failure_message,
    'failure_contents': failure_contents,
    'output': output
  }.reject! { |_, v| v.blank? }
end

#nameString

The name of the test case.


74
75
76
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 74

def name
  @test_case['name']
end

#outputString

The output from the function under test. Needs to be initialized by the test code.


121
122
123
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 121

def output
  @output ||= ('output')
end

#passed?Boolean

Checks if the test case has passed.


177
178
179
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 177

def passed?
  status == 'PASS'
end

#skipped?Boolean

Checks if the test case was skipped.


163
164
165
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 163

def skipped?
  status == 'SKIP'
end

#statusString

Checks the status of the test case Can either be 'PASS','FAIL' or 'SKIP'


185
186
187
# File 'lib/autoload/course/assessment/java/java_programming_test_case_report.rb', line 185

def status
  @test_case['status']
end