How not to test the value of a certain property?
-
Thursday, March 17, 2011 11:57 PM
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
-
Wednesday, March 23, 2011 7:22 AMOwner
See here for a discussion of the problem, and information about how to avoid it:
http://social.msdn.microsoft.com/Forums/en/pex/thread/df4435a5-249d-46ce-a0bb-a0216b0f6e77
Nikolai Tillmann- Proposed As Answer by Nikolai TillmannMicrosoft Employee, Owner Wednesday, March 23, 2011 7:22 AM

