test4requirements 0.1.0.alpha.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/example_fail_pend_omit.rb +58 -0
- data/examples/example_small.rb +35 -0
- data/examples/example_test4requirements.rb +68 -61
- data/examples/example_test4requirements_shoulda.rb +63 -59
- data/examples/test4requirements.rb +11 -0
- data/lib/test4requirements.rb +106 -98
- data/lib/test4requirements/requirement.rb +56 -35
- data/lib/test4requirements/requirementlist.rb +111 -18
- data/lib/test4requirements/shoulda.rb +114 -77
- data/lib/test4requirements/testcase.rb +10 -12
- data/unittest/check_compatibility.rb +65 -65
- data/unittest/unittest_requirement.rb +28 -19
- data/unittest/unittest_requirementlist.rb +50 -34
- data/unittest/{unittest_requirementlist_overview.rb → unittest_requirementlist_with_tests.rb} +257 -199
- data/unittest/unittest_shoulda.rb +123 -123
- data/unittest/unittest_testcase.rb +4 -4
- metadata +21 -17
@@ -0,0 +1,58 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Example with pening, omit...
|
3
|
+
|
4
|
+
Expected result:
|
5
|
+
Requirements overview:
|
6
|
+
Requirement ok was successfull tested (OK: test_ok(Examples::Test_requirement_small))
|
7
|
+
Requirement pend was unsuccessfull tested (Pending: test_pend(Examples::Test_requirement_small))
|
8
|
+
Requirement fail was unsuccessfull tested (Failure: test_fail(Examples::Test_requirement_small))
|
9
|
+
Requirement omit was unsuccessfull tested (Omission: test_omit(Examples::Test_requirement_small))
|
10
|
+
Requirement no_test was not tested
|
11
|
+
{:ok=>true, :pend=>false, :fail=>false, :omit=>false, :no_test=>nil}
|
12
|
+
|
13
|
+
=end
|
14
|
+
gem 'test-unit'#, '= 2.1.1'
|
15
|
+
|
16
|
+
$:.unshift('../lib')
|
17
|
+
require 'test4requirements.rb'
|
18
|
+
|
19
|
+
$req = Test4requirements::RequirementList.new('Testrequirements', :ok, :pend, :fail, :omit, :no_test )
|
20
|
+
#~ $req.log.outputters << Log4r::StdoutOutputter.new('stdout')
|
21
|
+
|
22
|
+
=begin
|
23
|
+
Define a user defined action after test execution.
|
24
|
+
=end
|
25
|
+
$req.do_after_tests{|reqlist|
|
26
|
+
puts reqlist.overview(nil)
|
27
|
+
}# if false
|
28
|
+
|
29
|
+
#
|
30
|
+
module Examples
|
31
|
+
=begin rdoc
|
32
|
+
Test requirements
|
33
|
+
=end
|
34
|
+
class Test_requirement_small < Test::Unit::TestCase
|
35
|
+
#Following requirements exist, and must be tested sucessfull
|
36
|
+
requirements $req
|
37
|
+
|
38
|
+
#Test requirement 1.
|
39
|
+
def test_ok()
|
40
|
+
assign_requirement(:ok) #this test is testing requirement 1
|
41
|
+
assert_equal(2,1+1)
|
42
|
+
end
|
43
|
+
def test_fail()
|
44
|
+
assign_requirement(:fail) #this test is testing requirement 1
|
45
|
+
assert_equal(3,1+1)
|
46
|
+
end
|
47
|
+
def test_pend()
|
48
|
+
assign_requirement(:pend) #this test is testing requirement 1
|
49
|
+
pend('X')
|
50
|
+
end
|
51
|
+
def test_omit()
|
52
|
+
assign_requirement(:omit) #this test is testing requirement 1
|
53
|
+
omit('X')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end #module Examples
|
57
|
+
|
58
|
+
__END__
|
@@ -0,0 +1,35 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Small example as template for quick test.
|
3
|
+
=end
|
4
|
+
gem 'test-unit'#, '= 2.1.1'
|
5
|
+
|
6
|
+
$:.unshift('../lib')
|
7
|
+
require 'test4requirements.rb'
|
8
|
+
|
9
|
+
$req = Test4requirements::RequirementList.new('Testrequirements', :req1)
|
10
|
+
#~ $req.log.outputters << Log4r::StdoutOutputter.new('stdout')
|
11
|
+
|
12
|
+
=begin
|
13
|
+
Define a user defined action after test execution.
|
14
|
+
=end
|
15
|
+
$req.do_after_tests{|reqlist|
|
16
|
+
puts reqlist.overview(nil)
|
17
|
+
}
|
18
|
+
|
19
|
+
#
|
20
|
+
module Examples
|
21
|
+
=begin rdoc
|
22
|
+
Test requirements
|
23
|
+
=end
|
24
|
+
class Test_requirement_small < Test::Unit::TestCase
|
25
|
+
#Following requirements exist, and must be tested sucessfull
|
26
|
+
requirements $req
|
27
|
+
|
28
|
+
#Test requirement 1.
|
29
|
+
def test_1()
|
30
|
+
assign_requirement(:req1) #this test is testing requirement 1
|
31
|
+
assert_equal(2,1+1)
|
32
|
+
assert_equal(2,1+1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end #module Examples
|
@@ -1,62 +1,69 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
Some examples, how you can use test4requirements in your test.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
=
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
1
|
+
=begin rdoc
|
2
|
+
Some examples, how you can use test4requirements in your test.
|
3
|
+
|
4
|
+
The test for the requirements are separated to two classes:
|
5
|
+
* Examples::Test_requirement_1_2 and
|
6
|
+
* Examples::Test_requirement_4
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
Expectes Testresults:
|
11
|
+
Requirements overview:
|
12
|
+
Requirement req1 was successfull tested (OK: test_1(Examples::Test_requirement_1_2))
|
13
|
+
Requirement req2 was unsuccessfull tested (Failure: test_2(Examples::Test_requirement_1_2))
|
14
|
+
Requirement req3 was not tested
|
15
|
+
Requirement req4 was successfull tested (OK: test_4(Examples::Test_requirement_4))
|
16
|
+
{:req1=>true, :req2=>false, :req3=>nil, :req4=>true}
|
17
|
+
|
18
|
+
=end
|
19
|
+
gem 'test-unit'#, '= 2.1.1'
|
20
|
+
|
21
|
+
$:.unshift('../lib')
|
22
|
+
require 'test4requirements.rb'
|
23
|
+
|
24
|
+
$req = Test4requirements::RequirementList.new('Testrequirements', :req1,:req2,:req3, :req4)
|
25
|
+
#~ $req.log.outputters << Log4r::StdoutOutputter.new('stdout')
|
26
|
+
#Define a user defined action after test execution.
|
27
|
+
$req.do_after_tests{|reqlist|
|
28
|
+
puts reqlist.overview(nil)
|
29
|
+
}
|
30
|
+
|
31
|
+
#
|
32
|
+
module Examples
|
33
|
+
=begin rdoc
|
34
|
+
Test requirements 1 and 2.
|
35
|
+
=end
|
36
|
+
class Test_requirement_1_2 < Test::Unit::TestCase
|
37
|
+
#Following requirements exist, and must be tested sucessfull
|
38
|
+
requirements $req
|
39
|
+
|
40
|
+
#Test requirement 1.
|
41
|
+
def test_1()
|
42
|
+
assign_requirement(:req1) #this test is testing requirement 1
|
43
|
+
assert_equal(2,1+1)
|
44
|
+
end
|
45
|
+
#Test requirement 2.
|
46
|
+
def test_2()
|
47
|
+
assign_requirement(:req2)
|
48
|
+
assert_equal(3,1+1)
|
49
|
+
end
|
50
|
+
#Test requirement 3, but without assignment to a requirement
|
51
|
+
def test_3()
|
52
|
+
#no assignment to requirement 3
|
53
|
+
pend 'pend'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
=begin rdoc
|
58
|
+
Test requirement 4.
|
59
|
+
=end
|
60
|
+
class Test_requirement_4 < Test::Unit::TestCase
|
61
|
+
#Following requirements exist, and must be tested sucessfull
|
62
|
+
requirements $req
|
63
|
+
#Test requirement 4.
|
64
|
+
def test_4()
|
65
|
+
assign_requirement(:req4) #this test is testing requirement 4
|
66
|
+
assert_equal(2,1+1)
|
67
|
+
end
|
68
|
+
end
|
62
69
|
end #module Examples
|
@@ -1,60 +1,64 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
Example code
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
=
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
=
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
#
|
40
|
-
should 'fullfill request
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
1
|
+
=begin rdoc
|
2
|
+
Example code how to use test4requirements with shoulda.
|
3
|
+
|
4
|
+
Defines Examples::Test_with_shoulda
|
5
|
+
|
6
|
+
Expected result:
|
7
|
+
|
8
|
+
Requirements overview:
|
9
|
+
Requirement req1 was successfull tested (OK: fullfill request 1 (req. of customer X/Examples::Test_with_shoulda))
|
10
|
+
Requirement req2 was unsuccessfull tested (Failure: fullfill request 2 (req. of customer X/Examples::Test_with_shoulda))
|
11
|
+
Requirement req3 was successfull tested (OK: request_3 (Examples::_with_shoulda/Examples::Test_with_shoulda))
|
12
|
+
Requirement req4 was successfull tested (OK: request_4 (Examples::_with_shoulda/Examples::Test_with_shoulda))
|
13
|
+
Requirement req5 was not tested
|
14
|
+
|
15
|
+
=end
|
16
|
+
|
17
|
+
$:.unshift('../lib')
|
18
|
+
gem 'test-unit'#, '= 2.1.1'
|
19
|
+
|
20
|
+
require 'test4requirements'
|
21
|
+
require 'test4requirements/shoulda'
|
22
|
+
#~ require 'shoulda'
|
23
|
+
|
24
|
+
$req = Test4requirements::RequirementList.new('Testrequirements', :req1,:req2,:req3, :req4, :req5)
|
25
|
+
#~ $req.log.outputters << Log4r::StdoutOutputter.new('stdout')
|
26
|
+
|
27
|
+
#
|
28
|
+
module Examples
|
29
|
+
=begin rdoc
|
30
|
+
Some examples, how you can use test4requirements with shoulda.
|
31
|
+
|
32
|
+
Details see examples/example_test4requirements_shoulda.rb
|
33
|
+
=end
|
34
|
+
class Test_with_shoulda < Test::Unit::TestCase
|
35
|
+
#Following requirements exist, and must be tested sucessfull
|
36
|
+
requirements $req
|
37
|
+
|
38
|
+
context 'req. of customer X' do
|
39
|
+
#Add requirement as parameter of should
|
40
|
+
should 'fullfill request 1', requirement: :req1 do
|
41
|
+
assert_equal(2,1+1)
|
42
|
+
end
|
43
|
+
#add requirement via requirement command
|
44
|
+
should 'fullfill request 2' do
|
45
|
+
assign_requirement(:req2) #this test is testing requirement 1
|
46
|
+
assert_equal(3,1+1)
|
47
|
+
end
|
48
|
+
end #context
|
49
|
+
|
50
|
+
#Examples outside a context
|
51
|
+
|
52
|
+
#Add requirement as parameter of should
|
53
|
+
should 'request_3', requirement: :req3 do
|
54
|
+
assert_equal(2,1+1)
|
55
|
+
end
|
56
|
+
|
57
|
+
#add requirement via requirement command
|
58
|
+
should 'request_4' do
|
59
|
+
assign_requirement(:req4) #this test is testing requirement 1
|
60
|
+
assert_equal(2,1+1)
|
61
|
+
end
|
62
|
+
|
63
|
+
end #MyTest_shoulda
|
60
64
|
end #module Examples
|
@@ -0,0 +1,11 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Example code to show how to use the test4requirements-gem.
|
3
|
+
|
4
|
+
The examples:
|
5
|
+
* examples/example_small.rb
|
6
|
+
* examples/example_test4requirements.rb
|
7
|
+
* examples/example_fail_pend_omit.rb
|
8
|
+
* examples/example_test4requirements_shoulda.rb
|
9
|
+
=end
|
10
|
+
module Examples
|
11
|
+
end #module Examples
|
data/lib/test4requirements.rb
CHANGED
@@ -1,98 +1,106 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
This gem is based on a
|
3
|
-
{question at stackoverflow}[http://stackoverflow.com/questions/6958586/are-there-any-good-ruby-testing-traceability-solutions]:
|
4
|
-
|
5
|
-
:: Are there any gems that'll allow me to implement traceability from my tests back to designs/requirements?
|
6
|
-
|
7
|
-
:: i.e.: I want to tag my tests with the name of the requirements they test, and then generate reports of requirements that aren't tested or have failing tests, etc.
|
8
|
-
|
9
|
-
:title:test4requirements Unit-Testing with assignment to requirements
|
10
|
-
|
11
|
-
=Usage
|
12
|
-
require 'test4requirements.rb'
|
13
|
-
|
14
|
-
==Define RequirementList and Requirements
|
15
|
-
You must define your requirements and a RequirementList.
|
16
|
-
|
17
|
-
You can make it with simple keys and without description:
|
18
|
-
$req = Test4requirements::RequirementList.new(:req1,:req2,:req3, :req4)
|
19
|
-
|
20
|
-
You may set an outputter to a logger:
|
21
|
-
$req.log.outputters << Log4r::StdoutOutputter.new('stdout')
|
22
|
-
|
23
|
-
|
24
|
-
Or you can define an empty list and assign requirements
|
25
|
-
with description etc.
|
26
|
-
$req = Test4requirements::RequirementList.new()
|
27
|
-
$req << Test4requirements::Requirement.new(
|
28
|
-
description: 'What is required',
|
29
|
-
reference: 'Customer Requirement, Version 2011-08-02, page 12'
|
30
|
-
)
|
31
|
-
|
32
|
-
==Define your test cases
|
33
|
-
|
34
|
-
With Test::Unit::TestCase.requirments you can assign a RequirementList to your tests.
|
35
|
-
class Test_requirement < Test::Unit::TestCase
|
36
|
-
#Following requirements exist, and must be tested sucessfull
|
37
|
-
requirements $req
|
38
|
-
# ...
|
39
|
-
end
|
40
|
-
|
41
|
-
A RequirementList can be assigned to multiply TestCase.
|
42
|
-
|
43
|
-
==Assign tests to requirements
|
44
|
-
Tests can by assigned to a requirement with
|
45
|
-
Test::Unit::TestCase#assign_requirement.
|
46
|
-
|
47
|
-
#Test requirement 1.
|
48
|
-
def test_1()
|
49
|
-
assign_requirement(:req1) #this test is testing requirement 1
|
50
|
-
assert_equal(2,1+1)
|
51
|
-
end
|
52
|
-
|
53
|
-
==Get the result
|
54
|
-
|
55
|
-
Unit-Test are executed at_exit. Your results are not available before the tests are ready.
|
56
|
-
|
57
|
-
There are three ways to get information.
|
58
|
-
|
59
|
-
===Standard reporting
|
60
|
-
|
61
|
-
Like the Unit-Test results the requirement-result are written at the end
|
62
|
-
with Test4requirements::RequirementList#overview
|
63
|
-
|
64
|
-
You can influence the output with Test4requirements::RequirementList#report_type=
|
65
|
-
|
66
|
-
===Logger
|
67
|
-
There is a logger. You have access to teh logger with Test4requirements::RequirementList#log.
|
68
|
-
You can define outputters to the logger, you may log in a file to get more informations.
|
69
|
-
You can log to STDOUT, but the logging will be mixed with the test output.
|
70
|
-
|
71
|
-
===User defined actions
|
72
|
-
Each action must be done at the end of the script.
|
73
|
-
You may use Test4requirements::RequirementList#do_after_tests to define an
|
74
|
-
action at the end of the script.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
1
|
+
=begin rdoc
|
2
|
+
This gem is based on a
|
3
|
+
{question at stackoverflow}[http://stackoverflow.com/questions/6958586/are-there-any-good-ruby-testing-traceability-solutions]:
|
4
|
+
|
5
|
+
:: Are there any gems that'll allow me to implement traceability from my tests back to designs/requirements?
|
6
|
+
|
7
|
+
:: i.e.: I want to tag my tests with the name of the requirements they test, and then generate reports of requirements that aren't tested or have failing tests, etc.
|
8
|
+
|
9
|
+
:title:test4requirements Unit-Testing with assignment to requirements
|
10
|
+
|
11
|
+
=Usage
|
12
|
+
require 'test4requirements.rb'
|
13
|
+
|
14
|
+
==Define RequirementList and Requirements
|
15
|
+
You must define your requirements and a RequirementList.
|
16
|
+
|
17
|
+
You can make it with simple keys and without description:
|
18
|
+
$req = Test4requirements::RequirementList.new(:req1,:req2,:req3, :req4)
|
19
|
+
|
20
|
+
You may set an outputter to a logger:
|
21
|
+
$req.log.outputters << Log4r::StdoutOutputter.new('stdout')
|
22
|
+
|
23
|
+
|
24
|
+
Or you can define an empty list and assign requirements
|
25
|
+
with description etc.
|
26
|
+
$req = Test4requirements::RequirementList.new()
|
27
|
+
$req << Test4requirements::Requirement.new(
|
28
|
+
description: 'What is required',
|
29
|
+
reference: 'Customer Requirement, Version 2011-08-02, page 12'
|
30
|
+
)
|
31
|
+
|
32
|
+
==Define your test cases
|
33
|
+
|
34
|
+
With Test::Unit::TestCase.requirments you can assign a RequirementList to your tests.
|
35
|
+
class Test_requirement < Test::Unit::TestCase
|
36
|
+
#Following requirements exist, and must be tested sucessfull
|
37
|
+
requirements $req
|
38
|
+
# ...
|
39
|
+
end
|
40
|
+
|
41
|
+
A RequirementList can be assigned to multiply TestCase.
|
42
|
+
|
43
|
+
==Assign tests to requirements
|
44
|
+
Tests can by assigned to a requirement with
|
45
|
+
Test::Unit::TestCase#assign_requirement.
|
46
|
+
|
47
|
+
#Test requirement 1.
|
48
|
+
def test_1()
|
49
|
+
assign_requirement(:req1) #this test is testing requirement 1
|
50
|
+
assert_equal(2,1+1)
|
51
|
+
end
|
52
|
+
|
53
|
+
==Get the result
|
54
|
+
|
55
|
+
Unit-Test are executed at_exit. Your results are not available before the tests are ready.
|
56
|
+
|
57
|
+
There are three ways to get information.
|
58
|
+
|
59
|
+
===Standard reporting
|
60
|
+
|
61
|
+
Like the Unit-Test results the requirement-result are written at the end
|
62
|
+
with Test4requirements::RequirementList#overview
|
63
|
+
|
64
|
+
You can influence the output with Test4requirements::RequirementList#report_type=
|
65
|
+
|
66
|
+
===Logger
|
67
|
+
There is a logger. You have access to teh logger with Test4requirements::RequirementList#log.
|
68
|
+
You can define outputters to the logger, you may log in a file to get more informations.
|
69
|
+
You can log to STDOUT, but the logging will be mixed with the test output.
|
70
|
+
|
71
|
+
===User defined actions
|
72
|
+
Each action must be done at the end of the script.
|
73
|
+
You may use Test4requirements::RequirementList#do_after_tests to define an
|
74
|
+
action at the end of the script.
|
75
|
+
|
76
|
+
|
77
|
+
=Examples
|
78
|
+
See examples/test4requirements.rb for some examples.
|
79
|
+
|
80
|
+
=Known problems
|
81
|
+
==Compatibility
|
82
|
+
Ruby 1.9.1 needs test-unit-gem lower equal 2.1.1.
|
83
|
+
|
84
|
+
=end
|
85
|
+
|
86
|
+
gem 'test-unit'
|
87
|
+
=begin
|
88
|
+
unittest 2.3.1:
|
89
|
+
Test::Unit::Assertions uses Encoding#ascii_compatible?
|
90
|
+
Is not defined in ruby 1.9.1 (at least my installation ;) )
|
91
|
+
=end
|
92
|
+
gem 'test-unit', '<= 2.1.1' if RUBY_VERSION == '1.9.1'
|
93
|
+
require 'test/unit'
|
94
|
+
|
95
|
+
module Test4requirements
|
96
|
+
VERSION = '0.1.0'
|
97
|
+
end
|
98
|
+
require 'log4r'
|
99
|
+
require_relative 'test4requirements/testcase'
|
100
|
+
require_relative 'test4requirements/requirement'
|
101
|
+
require_relative 'test4requirements/requirementlist'
|
102
|
+
|
103
|
+
#Not loaded by default.
|
104
|
+
#require_relative 'test4requirements/shoulda'
|
105
|
+
|
106
|
+
|