我正在将我们所有的系统测试与测试用例和我们的需求联系起来。每个需求都有一个ID。每个测试用例/系统测试测试各种各样的需求。每个模块的代码链接到多个需求。
我正试图找到最好的方法,将每个系统测试与其驱动需求联系起来。
我希望做这样的事情:
[NUnit.Framework.Property("Release", "6.0.0")]
[NUnit.Framework.Property("Requirement", "FR50082")]
[NUnit.Framework.Property("Requirement", "FR50084")]
[NUnit.Framework.Property("Requirement", "FR50085")]
[TestCase(....)]
public void TestSomething(string a, string b...)但是,这将中断,因为属性是键值对.系统将不允许我具有相同密钥的多个属性。
我希望这样做的原因是,如果一个模块发生了涉及到这些需求的更改,那么它能够在我们的系统中测试特定的需求。
与其在每个构建上运行超过1,000个系统测试,我们还可以根据代码所做的更改来确定测试目标。
有些系统测试运行时间超过5分钟(企业医疗系统),因此“只运行所有这些测试”并不是一个可行的解决方案。我们这样做,但只是在通过我们的环境进行宣传之前。
有什么想法?
发布于 2014-03-05 03:11:24
您考虑过从自定义属性派生的NUnit.Framework.Property吗?
从LINQPad 4“查询”(语言设置为C# Program )和对nunit.framework.dll (版本2.4.8)的引用(Version2.4.8)来看,以下类似的内容可能对您有用:
// main method to exercise a our PoC test case
void Main()
{
TestSomething("a", "b");
}
// our PoC custom property attribute
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)]
public class RequirementsAttribute : NUnit.Framework.PropertyAttribute
{
public RequirementsAttribute(string[] requirements)
: base(requirements)
{
}
}
// a test case using our custom property attribute to relate it to multiple requirements
[Requirements(new string[] { "FR50082", "FR50084" })]
[TestCase("PoCTest")]
public void TestSomething(string a, string b)
{
// blah, blah, blah
Assert.AreNotEqual(a, b);
}发布于 2014-05-27 21:20:58
由于某些原因,我无法在上面的评论中添加到google讨论帖子的链接,所以我也在这里添加了这个帖子。(链接为https://groups.google.com/forum/#!topic/nunit-discuss/ndV3VTPndck)
类别要求:FR12345 12345
代码:
public class RequirementAttribute : CategoryAttribute
{
public RequirementAttribute(string s)
: base("Requirement:" + s)
{ }
}代码:
public class RequirementAttribute : PropertyAttribute
{
public RequirementAttribute(string s)
: base(s)
{}
}4:如果您希望每个测试都有多个需求,并且仍然有类似于(3)中的显示,那么您必须使键是唯一的。不需要看上去太糟。在下面的代码中,我刚刚给它添加了一个计数器。它将显示如下:
要求-1FR12345
要求-2FR23456
代码:
public class RequirementAttribute : PropertyAttribute
{
public RequirementAttribute(string[] array)
{
int i = 0;
foreach (var s in array)
{
Properties.Add("Requirement-" + i, s);
i++;
}
}
}你用它就像:
[Requirement(new[] { "1234", "2345" })]
[Test]
public void Test()
{ }(如果您想要一个没有"new“的语法,前面的答案显示了使用param的语法。)
选项4将不按需求编号分组,而是按计数器分组。如果要按需求编号分组,可以使用选项5:
要求-FR12345 12345
这样,您还可以跳过前缀,并在TE中将每个需求作为自己的类别。
代码:
public class RequirementAttribute : PropertyAttribute
{
public RequirementAttribute(string[] array)
{
foreach (var s in array)
{
Properties.Add("Requirement-" + s,"");
}
}
}当然,你也可以跳过前缀。
https://stackoverflow.com/questions/22187229
复制相似问题