How not to test the value of a certain property?

已锁定 How not to test the value of a certain property?

  • Thursday, March 17, 2011 11:57 PM
     
      Has Code

    I have a class similar to this:

    class Foo
    
    {
    
     public DateTime Created { get; set; }
    
     // etc. properties
    
     public Foo() {
    
       Created = DateTime.Now;
    
     }
    
    }
    
    

    And when I run Pex it generates silly code that always fails because:

    [TestMethod]
    
    [PexGeneratedBy(typeof(FooTest))]
    
    public void FooTest984()
    
    {
    
     Foo foo;
    
     foo = FooFactory.CreateFoo();
    
     Assert.IsNotNull((object)foo);
    
     ...
    
     Assert.AreEqual<int>(17, ((Foo)foo).Created.Day);
    
     Assert.AreEqual<DayOfWeek>
    
      (DayOfWeek.Thursday, ((Foo)foo).Created.DayOfWeek);
    
     Assert.AreEqual<int>(76, ((Foo)foo).Created.DayOfYear);
    
     Assert.AreEqual<int>(18, ((Foo)foo.Created.Hour);
    
     Assert.AreEqual<DateTimeKind>
    
      (DateTimeKind.Local, ((Foo)foo).Created.Kind);
    
     Assert.AreEqual<int>(71, ((Foo)foo).Created.Millisecond);
    
     Assert.AreEqual<int>(52, ((Foo)foo).Created.Minute);
    
     // etc.
    
    }
    
    
    
    

    What is the suggested practice for (skipping of) testing values like this?

    Thanks

    Val

    • Edited by Valo Friday, March 18, 2011 12:02 AM edited
    •  

All Replies