我正在尝试在我的项目中使用Pex进行探索性测试。但是,我不能让它以我现有的测试作为测试种子运行。
我已成功使用[PexArguments]提供输入testdata。 为了验证,我现在已经按照教程并实现了Capitalize功能。 当我现在运行Pex时,将执行作为注释定义的测试用例。 但是,不执行方法中定义的测试。我按照说明here。
如果它很重要:我使用的是VisualStudio 2010,而Pex在版本0.94中表示它。
有人知道我做错了吗?
这是我的测试课程:
[PexAllowedExceptionFromTypeUnderTest(typeof(InvalidOperationException))]
[PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException), AcceptExceptionSubtypes = true)]
public partial class Class1Test
{
/// <summary>Test stub for Capitalize(String)</summary>
[PexMethod]
[PexArguments("foo")]
public string Capitalize(string value)
{
string result = Class1.Capitalize(value);
return result;
// TODO: add assertions to method Class1Test.Capitalize(String)
}
[TestMethod]
public void CapitalizeSeed()
{
string result = this.Capitalize("foo2");
Assert.AreEqual("Foo", result);
}
}
答案 0 :(得分:2)
Pex将从测试方法CapitalizeSeed(...)中获取值,并使用它来为其探索提供种子。但是,它不会执行TestMethod本身。 当您从Visual Studio中运行Pex时,您应该看到在“value”列下报告的“foo2”作为输入之一。在返回语句之前的PexMethod中断言,如下所示: PexAssert.AreEqual(“Foo”,result); 你应该看到失败的测试用例。