有没有好的ruby测试可追溯性解决方案?
我正在编写一些ruby(不是Rails)并使用test/unit和shoulda来编写测试 是否有任何gem允许我实现从测试到设计/需求的可追溯性 i、 例如:我想用他们测试的需求的名称标记我的测试,然后生成未测试或测试失败的需求的报告,等等 希望这对ruby来说不是太有进取心 谢谢 您可以将您的需求作为测试,没有比这更具可追溯性的了:) 所以一个需求就是一个特性,而一个特性有您想要测试的场景有没有好的ruby测试可追溯性解决方案?,ruby,testing,testunit,traceability,Ruby,Testing,Testunit,Traceability,我正在编写一些ruby(不是Rails)并使用test/unit和shoulda来编写测试 是否有任何gem允许我实现从测试到设计/需求的可追溯性 i、 例如:我想用他们测试的需求的名称标记我的测试,然后生成未测试或测试失败的需求的报告,等等 希望这对ruby来说不是太有进取心 谢谢 您可以将您的需求作为测试,没有比这更具可追溯性的了:) 所以一个需求就是一个特性,而一个特性有您想要测试的场景 # addition.feature Feature: Addition In order to
# addition.feature
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario Outline: Add two numbers
Given I have entered <input_1> into the calculator
And I have entered <input_2> into the calculator
When I press <button>
Then the result should be <output> on the screen
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
更新:此解决方案作为gem提供:
有什么宝石可以让我从我的
测试返回到设计/要求
我不知道任何宝石,但你的需要是一个小实验的灵感,如何解决它
- 你必须用需求列表定义你的需求。新的(1,2,3,4)
- 该需求可以在测试用例中与需求一起分配
- 每个测试都可以分配给一个有需求的需求
- 测试结果之后,您可以了解测试了哪些需求(成功)
gem 'test-unit'
require 'test/unit'
###########
# This should be a gem
###########
class Test::Unit::TestCase
def self.requirements(req)
@@requirements = req
end
def requirement(req)
raise RuntimeError, "No requirements defined for #{self}" unless defined? @@requirements
caller.first =~ /:\d+:in `(.*)'/
@@requirements.add_test(req, "#{self.class}##{$1}")
end
alias :run_test_old :run_test
def run_test
run_test_old
#this code is left if a problem occured.
#in other words: if we reach this place, then the test was sucesfull
if defined? @@requirements
@@requirements.test_successfull("#{self.class}##{@method_name}")
end
end
end
class RequirementList
def initialize( *reqs )
@requirements = reqs
@tests = {}
@success = {}
#Yes, we need two at_exit.
#tests are done also at_exit. With double at_exit, we are after that.
#Maybe better to be added later.
at_exit {
at_exit do
self.overview
end
}
end
def add_test(key, loc)
#fixme check duplicates
@tests[key] = loc
end
def test_successfull(loc)
#fixme check duplicates
@success[loc] = true
end
def overview()
puts "Requirements overiew"
@requirements.each{|req|
if @tests[req] #test defined
if @success[@tests[req]]
puts "Requirement #{req} was tested in #{@tests[req] }"
else
puts "Requirement #{req} was unsuccessfull tested in #{@tests[req] }"
end
else
puts "Requirement #{req} was not tested"
end
}
end
end #RequirementList
###############
## Here the gem end. The test will come.
###############
$req = RequirementList.new(1,2,3, 4)
class MyTest < Test::Unit::TestCase
#Following requirements exist, and must be tested sucessfull
requirements $req
def test_1()
requirement(1) #this test is testing requirement 1
assert_equal(2,1+1)
end
def test_2()
requirement(2)
assert_equal(3,1+1)
end
def test_3()
#no assignment to requirement 3
pend 'pend'
end
end
class MyTest_4 < Test::Unit::TestCase
#Following requirements exist, and must be tested sucessfull
requirements $req
def test_4()
requirement(4) #this test is testing requirement 4
assert_equal(2,1+1)
end
end
gem“测试单元”
需要“测试/单元”
###########
#这应该是一块宝石
###########
类测试::单元::测试用例
def自我要求(req)
@@要求=req
结束
def要求(req)
raise RUNTIMERROR,“没有为#{self}定义任何要求”,除非已定义@@要求
caller.first=~/:\d+:in`(.*)中/
@@需求。添加测试(req,“#{self.class}##{$1}”)
结束
别名:run\u test\u旧:run\u test
def运行测试
运行测试
#如果出现问题,则留下此代码。
#换句话说,如果我们到达这个地方,那么测试就成功了
如果定义@@要求
@@需求。测试成功(“#{self.class}#{@method_name}”)
结束
结束
结束
课程要求表
def初始化(*reqs)
@需求=需求
@测试={}
@成功={}
#是的,我们需要两个在出口。
#测试也在_出口处进行。在双出口的情况下,我们正在追查。
#也许以后再添加更好。
出口处{
在你出口吗
自我概述
结束
}
结束
def添加_测试(钥匙,loc)
#修复我检查副本
@测试[键]=loc
结束
def测试成功(loc)
#修复我检查副本
@成功[loc]=正确
结束
def概述()
将“需求概述”
@要求.每项{|要求|
如果@tests[req]#定义了测试
如果@success[@tests[req]]
puts“需求#{req}在#{@tests[req]}中测试”
其他的
puts“在{@tests[req]}中测试需求{req}未成功”
结束
其他的
puts“未测试需求#{req}”
结束
}
结束
结束#需求列表
###############
##这里是宝石的尽头。考试就要来了。
###############
$req=需求列表。新增(1,2,3,4)
类MyTest
结果是:
Loaded suite testing_traceability_solutions
Started
.FP.
1) Failure:
test_2(MyTest)
[testing_traceability_solutions.rb:89:in `test_2'
testing_traceability_solutions.rb:24:in `run_test']:
<3> expected but was
<2>.
2) Pending: pend
test_3(MyTest)
testing_traceability_solutions.rb:92:in `test_3'
testing_traceability_solutions.rb:24:in `run_test'
Finished in 0.65625 seconds.
4 tests, 3 assertions, 1 failures, 0 errors, 1 pendings, 0 omissions, 0 notifications
50% passed
Requirements overview:
Requirement 1 was tested in MyTest#test_1
Requirement 2 was unsuccessfull tested in MyTest#test_2
Requirement 3 was not tested
Requirement 4 was tested in MyTest_4#test_4
加载套件测试\u可追溯性\u解决方案
起动
.FP。
1) 失败:
测试2(MyTest)
[测试可追溯性解决方案.rb:89:in `测试2'
测试可追溯性解决方案。rb:24:在“运行测试”中]:
预料之中,但事实并非如此
.
2) 待决:待决
测试3(MyTest)
测试可追溯性解决方案。rb:92:in'test_3'
测试可追溯性解决方案。rb:24:在“运行测试”中
以0.65625秒完成。
4次测试,3次断言,1次失败,0次错误,1次挂起,0次遗漏,0次通知
50%通过
需求概述:
需求1在MyTest#test#U 1中进行了测试
要求2在MyTest#test#U 2中测试未成功
没有测试要求3
要求4在MyTest#U 4#test#U 4中进行了测试
如果你认为,这可能是你的解决方案,请给我一个反馈。然后我会尝试用它来建造一块宝石
与shoulda一起使用的代码示例
#~ require 'test4requirements' ###does not exist/use code above
require 'shoulda'
#use another interface ##not implemented###
#~ $req = Requirement.new_from_file('requirments.txt')
class MyTest_shoulda < Test::Unit::TestCase
#Following requirements exist, and must be tested sucessfull
#~ requirements $req
context 'req. of customer X' do
#Add requirement as parameter of should
# does not work yet
should 'fullfill request 1', requirement: 1 do
assert_equal(2,1+1)
end
#add requirement via requirement command
#works already
should 'fullfill request 1' do
requirement(1) #this test is testing requirement 1
assert_equal(2,1+1)
end
end #context
end #MyTest_shoulda
#~require'test4requirements'####不存在/使用上述代码
需要“shoulda”
#使用另一个未实现的接口###
#~$req=Requirement.new\u来自\u文件('requirements.txt')
类MyTest\u shoulda
看起来不错,但我不确定它是否适合我。例如,我的一个测试检查一个方法的返回值,该方法是一个包含大约150个元素的3D数组。我用黄瓜怎么做?(我已经在test/unit中写过了。)这看起来是个好主意——不过我正在考虑以另一种方式推出自己的。我的需求在一个txt文件中,每个文件都有一个标签[REQnnnn]。然后在每个测试中将该标记添加到should
行(我使用的是shoulda)。我的最后一步是编写一个TestRunner类,该类运行单元测试,获取输出并对照需求txt文件进行交叉检查。谢谢你的启发。我刚刚添加了一个与shoulda一起使用的代码示例。李,你觉得怎么样
#~ require 'test4requirements' ###does not exist/use code above
require 'shoulda'
#use another interface ##not implemented###
#~ $req = Requirement.new_from_file('requirments.txt')
class MyTest_shoulda < Test::Unit::TestCase
#Following requirements exist, and must be tested sucessfull
#~ requirements $req
context 'req. of customer X' do
#Add requirement as parameter of should
# does not work yet
should 'fullfill request 1', requirement: 1 do
assert_equal(2,1+1)
end
#add requirement via requirement command
#works already
should 'fullfill request 1' do
requirement(1) #this test is testing requirement 1
assert_equal(2,1+1)
end
end #context
end #MyTest_shoulda