为什么运行 Pex Explorations 会导致忽略之前 Pex 生成的测试方法?
正在测试的代码:
public class TestReader
{
public string Content { get; private set; }
public void LoadFile(string fileName)
{
var content = FileSystem.ReadAllText(fileName);
if (!content.StartsWith("test"))
throw new ArgumentException("invalid file");
this.Content = content;
}
}
public static class FileSystem
{
public static string ReadAllText(string fileName)
{
return File.ReadAllText(fileName);
}
}
测试项目中的 Pex 方法:
[PexMethod]
public void CheckValidFileWithPex(string content)
{
// arrange
var fileName = "test.txt";
Moles_Example.Moles.MFileSystem.ReadAllTextString =
delegate(string f)
{
Assert.IsTrue(f == fileName); return content;
};
// act
var test = new TestReader();
test.LoadFile(fileName);
// assert
Assert.AreEqual(content, test.Content);
}
当我第一次在 CheckValidFileWithPex(string content)
上运行“Pex Explorations”时,会生成五个测试方法,其中 content
的值如下:
- null
- ""
- "\0\0\0\0"
- "test"
- "\0\0\0\0\0"
但是,如果我再次运行“Pex Explorations”,则不会发生任何更改生成的测试,现有的测试项目代码,或第二次执行之前的主项目,则仅列出 4 个已生成的测试,并且缺少第 3 项(“\0\0\0\0”) 的测试输入。
Pex生成的测试文件的源代码仍然有这种情况的测试方法,但我不明白为什么这种情况没有列在Pex探索结果中。
感谢您的见解。
Code being tested:
public class TestReader
{
public string Content { get; private set; }
public void LoadFile(string fileName)
{
var content = FileSystem.ReadAllText(fileName);
if (!content.StartsWith("test"))
throw new ArgumentException("invalid file");
this.Content = content;
}
}
public static class FileSystem
{
public static string ReadAllText(string fileName)
{
return File.ReadAllText(fileName);
}
}
Pex method in test project:
[PexMethod]
public void CheckValidFileWithPex(string content)
{
// arrange
var fileName = "test.txt";
Moles_Example.Moles.MFileSystem.ReadAllTextString =
delegate(string f)
{
Assert.IsTrue(f == fileName); return content;
};
// act
var test = new TestReader();
test.LoadFile(fileName);
// assert
Assert.AreEqual(content, test.Content);
}
When I first run "Pex Explorations" on CheckValidFileWithPex(string content)
, five test methods are generated with the following values for content
:
- null
- ""
- "\0\0\0\0"
- "test"
- "\0\0\0\0\0"
However, if I run "Pex Explorations" again, no changes made to the generated tests, existing test project code, or main project prior to second execution, then only 4 tests are listed as generated and the test input from item 3 ("\0\0\0\0") is missing.
The source code of the Pex-generated test file still has a test method for this case, but I do not understand why this case is not listed in Pex Exploration Results.
Thank you for your insight.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论