正在测试的代码:
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);
}
当我第一次在 上运行“Pex Explorations”时CheckValidFileWithPex(string content)
,会生成五种测试方法,它们的值如下content
:
- 无效的
- “”
- “\0\0\0\0”
- “测试”
- “\0\0\0\0\0”
但是,如果我再次运行“Pex Explorations”,在第二次执行之前没有对生成的测试、现有的测试项目代码或主项目进行任何更改,那么只有 4 个测试被列为生成的并且来自项目 3 的测试输入(“\ 0\0\0\0")丢失。
Pex生成的测试文件的源代码中还有这个案例的测试方法,但是我不明白为什么这个案例没有在Pex Exploration Results中列出。
感谢您的见解。