Question

I'm using VS2013/CodedUI and in my [TestMethod] I assert as following:

Assert.IsTrue(String.Equals(logo.GetModifiedBy(), "Vendor2"));

And this fails as expected in my test case but the message in the Output is simply as shown below, is there a way to also report the data used to compare? I searched but didn't find much

Message: Assert.IsTrue failed
Was it helpful?

Solution

Try using Assert.AreEqual:

Assert.AreEqual("Vendor2", logo.GetModifiedBy());

The exception message generated will indicate both the expected and actual value.

Of course, you could also just provide a custom message using this overload of IsTrue:

var modifiedBy = logo.GetModifiedBy();
Assert.IsTrue(
    String.Equals(modifiedBy, "Vendor2"), 
    "Incorrect ModifiedBy value: '{0}'", 
    modifiedBy);

OTHER TIPS

Each Assert method has an overload that takes a string message. The following would give you what you want, although I agree with @p.s.w.g that Assert.AreEqual() is probably what you want. Assert.AreEqual() also supports a custom message.

Assert.IsTrue(String.Equals(logo.GetModifiedBy(), "Vendor2"), string.Format("{0} does not match {1}", logo.GetModifiedBy(), "Vendor2"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top