2015-05-08 42 views
0

我试图将下面的pex testmethod转换为正常的单元测试。虽然我打算在需要的地方使用Microsoft Fakes,但我首先要理解几件事情。使用Microsoft Fakes将VS 2010的Pex TestMethods转换为VS2013

[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到测试方法 ?
  • 我看到nameValueCollection中的计数。返回的计数值是1.是否因为我插入的所有KeyValuePair都是相同的?

回答

1

您的新测试似乎缺少将keyValuePairs阵列的内容复制到nameValueCollection集合中的步骤。我相信这是在原来的测试中完成的这条线:

nameValueCollection = PexFactories.CreateNameValueCollection(keyValuePairs); 
+0

我忘了在这篇文章中添加该步骤。除此之外还有其他评论吗? – krrishna

+0

如果你已经做了这个修复,我没有看到在第一个测试中会涉及到的任何情况,这些情况在第二个测试中没有涉及。我有一个假设,这一行:'this.Inialialize(errorLog,“”,nameValueCollection);'在功能上等同于这一行:'errorLog.Initialize(“”,nameValueCollection);' –

+0

是的,它是转换。 – krrishna