使用Microsoft假货将VS 2010的PEX测试方法转换为VS2013



我试图将以下PEX测试方法转换为普通单位测试。尽管我打算在需要的地方使用Microsoft假货,但我想先了解一些事情。

[TestMethod]
[PexGeneratedBy(typeof(ErrorLogTest))]
public void Initialize139()
{
    ErrorLog errorLog;
    NameValueCollection nameValueCollection;
    errorLog = new ErrorLog();
    errorLog.MyProperty = false;
    KeyValuePair<string, string>[] keyValuePairs = new KeyValuePair<string, string>[5];
    KeyValuePair<string, string> s0 = new KeyValuePair<string, string>("", "");
    keyValuePairs[0] = s0;
    KeyValuePair<string, string> s1 = new KeyValuePair<string, string>("", "");
    keyValuePairs[1] = s1;
    KeyValuePair<string, string> s2 = new KeyValuePair<string, string>("", "");
    keyValuePairs[2] = s2;
    KeyValuePair<string, string> s3 = new KeyValuePair<string, string>("", "");
    keyValuePairs[3] = s3;
    KeyValuePair<string, string> s4 = new KeyValuePair<string, string>("", "");
    keyValuePairs[4] = s4;
    nameValueCollection = PexFactories.CreateNameValueCollection(keyValuePairs);
    this.Initialize(errorLog, "", nameValueCollection);
    Assert.IsNotNull((object)errorLog);
    Assert.AreEqual<bool>(false, errorLog.MyProperty);
}

我已经将其转换为一个简单的单元测试,如下所示:

[TestMethod]
public void Initialize1390()
{
    ErrorLog errorLog;
    NameValueCollection nameValueCollection = new NameValueCollection();
    errorLog = new ErrorLog();
    errorLog.MyProperty = false;
    KeyValuePair<string, string>[] keyValuePairs = new KeyValuePair<string, string>[5];
    KeyValuePair<string, string> s0 = new KeyValuePair<string, string>("", "");
    keyValuePairs[0] = s0;
    KeyValuePair<string, string> s1 = new KeyValuePair<string, string>("", "");
    keyValuePairs[1] = s1;
    KeyValuePair<string, string> s2 = new KeyValuePair<string, string>("", "");
    keyValuePairs[2] = s2;
    KeyValuePair<string, string> s3 = new KeyValuePair<string, string>("", "");
    keyValuePairs[3] = s3;
    KeyValuePair<string, string> s4 = new KeyValuePair<string, string>("", "");
    keyValuePairs[4] = s4;                
    errorLog.Initialize("", nameValueCollection);
    Assert.IsNotNull((object)errorLog);
    Assert.AreEqual<bool>(false, errorLog.MyProperty);
}

我在这里有两个问题:

  • 我是否会在从pexmethod到testMethod的这种转换中失去任何场景?
  • 我在名称valuecollection中看到了计数。返回计数值为1。是因为我插入的所有keyvaluepair都是相同的吗?

您的新测试似乎缺少您将keyValuePairs数组内容复制到nameValueCollection集合中的步骤。我相信这是在此行的原始测试中完成的:

nameValueCollection = PexFactories.CreateNameValueCollection(keyValuePairs);

最新更新