Class: Testmgr::TestCase

Inherits:
AbstractTest show all
Defined in:
lib/testmgr/base/test_case.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractTest

#name, #xpath

Instance Method Summary collapse

Constructor Details

#initialize(_id, desc = nil) ⇒ TestCase

Returns a new instance of TestCase.



13
14
15
16
17
18
19
20
21
# File 'lib/testmgr/base/test_case.rb', line 13

def initialize(_id, desc=nil)
  @test_id=_id
  @description=desc

  @assertions=[]
  @metrics={:passed => 0, :failed => 0, :skipped => 0, :total => 0 }

  super(@test_id)
end

Instance Attribute Details

#assertionsObject

Returns the value of attribute assertions.



10
11
12
# File 'lib/testmgr/base/test_case.rb', line 10

def assertions
  @assertions
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/testmgr/base/test_case.rb', line 9

def description
  @description
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/testmgr/base/test_case.rb', line 7

def id
  @id
end

#metricsObject

Returns the value of attribute metrics.



11
12
13
# File 'lib/testmgr/base/test_case.rb', line 11

def metrics
  @metrics
end

#parentObject

Returns the value of attribute parent.



8
9
10
# File 'lib/testmgr/base/test_case.rb', line 8

def parent
  @parent
end

#test_idObject

Returns the value of attribute test_id.



7
8
9
# File 'lib/testmgr/base/test_case.rb', line 7

def test_id
  @test_id
end

Instance Method Details

#add(rc, desc) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/testmgr/base/test_case.rb', line 27

def add(rc, desc)

  puts __FILE__ + (__LINE__).to_s + " TestCase.add(#{rc}, #{desc})"
  @assertions << { :rc => rc, :description => desc }

  if rc.nil?
    @metrics[:skipped]+=1
  elsif rc
    @metrics[:passed]+=1
  else
    @metrics[:failed]+=1
  end

  @metrics[:total]+=1
end

#calcResultObject



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/testmgr/base/test_case.rb', line 83

def calcResult()

  if @assertions.length < 1
    return nil
  end

  rc=true
  @assertions.each do |a|
    rc = rc && a[:rc]
  end

  rc
end

#child(name) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/testmgr/base/test_case.rb', line 72

def child(name)
 # puts __FILE__ + (__LINE__).to_s + " child(#{name}) matches #{@test_id} ??"
  if name == @test_id
 #   puts __FILE__ + (__LINE__).to_s + "Matched #{name} (#{@test_id})"
    return self
  end

  #    puts __FILE__ + (__LINE__).to_s + " No match #{name} (#{@test_id})"
  nil
end

#failed?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/testmgr/base/test_case.rb', line 101

def failed?
  !passed?
end

#get_nameObject



48
49
50
# File 'lib/testmgr/base/test_case.rb', line 48

def get_name
  @test_id
end

#get_time_requiredObject



64
65
66
# File 'lib/testmgr/base/test_case.rb', line 64

def get_time_required
  2.5
end

#getResultObject



23
24
25
# File 'lib/testmgr/base/test_case.rb', line 23

def getResult()
  @metrics[:total] > 0 && @metrics[:passed] > 0 && @metrics[:failed]==0
end

#passed?Boolean

Returns:

  • (Boolean)


105
106
107
108
# File 'lib/testmgr/base/test_case.rb', line 105

def passed?
  _rc=calcResult()
  !_rc.nil? && _rc
end


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/testmgr/base/test_case.rb', line 110

def print
  s="[requirement - #{parent.name}]:#{@test_id} - #{@description.to_s} : #{@metrics[:passed]}/#{@metrics[:total]} passed: #{calcResult().to_s}"

  if @id
    s += ":#{@id}"
  end

  i=0
  @assertions.each do |a|
    s += "\n  #{i}. " + a[:description].to_s + " : " + a[:rc].to_s
    i+=1
  end

  puts s
  s
end

#set_id(id) ⇒ Object



52
53
54
55
# File 'lib/testmgr/base/test_case.rb', line 52

def set_id(id)
  @id=id
  self
end

#set_name(name) ⇒ Object



57
58
59
60
# File 'lib/testmgr/base/test_case.rb', line 57

def set_name(name)
  @test_id=name
  self
end

#set_parent(parent) ⇒ Object



43
44
45
46
# File 'lib/testmgr/base/test_case.rb', line 43

def set_parent(parent)
   #   puts __FILE__ + (__LINE__).to_s + " TestComponent::set_parent"
  @parent=parent
end

#total_number_basic_tasksObject



68
69
70
# File 'lib/testmgr/base/test_case.rb', line 68

def total_number_basic_tasks
  3
end

#totalAssertionsObject



97
98
99
# File 'lib/testmgr/base/test_case.rb', line 97

def totalAssertions()
  @assertions.length
end