如何编写综合的单元测试方案(3)

发表于:2012-06-27来源:伯乐在线作者:李琼点击数: 标签:单元测试
[TestMethod] 1 2 3 4 5 6 public void Person_IsChanged_Changed_By_Setting_FirstName() { var person = new Person( Adam , Smith ); person.FirstName = Bob ; Assert.IsTrue(person.IsChanged); } 当然,如果

  [TestMethod]

1
2
3
4
5
6
public void Person_IsChanged_Changed_By_Setting_FirstName()
 {
 var person = new Person("Adam", "Smith");
 person.FirstName = "Bob";
 Assert.IsTrue(person.IsChanged);
 }

  当然,如果这些属性改变了,我们需要获取到属性改变通知:

  [TestMethod]

1
2
3
4
5
6
7
public void Person_IsChanged_Property_Change_Notification_By_Setting_FirstName()
 {
 var person = new Person("Adam", "Smith");
 var eventAssert = new PropertyChangedEventAssert(person);
 person.FirstName = "Bob";
 eventAssert.Expect("IsChanged");
 }

  [TestMethod]

1
2
3
4
5
6
7
8
9
public void Person_FullName_Property_Change_Notification_By_Setting_FirstName()
 {
 var person = new Person("Adam", "Smith");
 var eventAssert = new PropertyChangedEventAssert(person);
 person.FirstName = "Bob";
 eventAssert.SkipEvent(); //this was IsChanged
 eventAssert.SkipEvent(); //this was FirstName
 eventAssert.Expect("FullName");
 }

原文转自:http://www.ltesting.net