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.



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

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.



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

def assertions
  @assertions
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#metricsObject

Returns the value of attribute metrics.



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

def metrics
  @metrics
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#test_idObject

Returns the value of attribute test_id.



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

def test_id
  @test_id
end

Instance Method Details

#add(rc, desc) ⇒ Object



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

def 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



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/testmgr/base/test_case.rb', line 80

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



69
70
71
72
73
74
75
76
77
78
# File 'lib/testmgr/base/test_case.rb', line 69

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

#get_nameObject



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

def get_name
  @test_id
end

#get_time_requiredObject



61
62
63
# File 'lib/testmgr/base/test_case.rb', line 61

def get_time_required
  2.5
end

#getResultObject



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

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


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/testmgr/base/test_case.rb', line 94

def print
  s="[requirement - #{parent.name}]:#{@test_id} - #{@description.to_s} : #{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
end

#set_id(id) ⇒ Object



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

def set_id(id)
  @id=id
  self
end

#set_name(name) ⇒ Object



54
55
56
57
# File 'lib/testmgr/base/test_case.rb', line 54

def set_name(name)
  @test_id=name
  self
end

#set_parent(parent) ⇒ Object



40
41
42
43
# File 'lib/testmgr/base/test_case.rb', line 40

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

#total_number_basic_tasksObject



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

def total_number_basic_tasks
  3
end