简体   繁体   中英

Output of Visual Studio unit tests

I would like to know if it's possible to return some kind of value, bool, string or int for example from unit test methods.

For example I have this method:

[TestMethod]
public bool TestMetho()
{
    var SY = calc.GetUserInfo(new DateTime(2015, 12, 15));
    bool isOK = Assert.AreEqual(new DateTime(2015, 11, 29), SY);
    return bool;
}

I would like to reference the unit class methods from a console app and then print out the results. Is it possible to do something like this, because at this time I'm not able to assign the Assert.AreEqual method to some output variable.

You sure can.

  1. Add a reference to System.Diagnostics .
  2. Make sure you choose Debug when you go to run your test.
  3. Use Debug.WriteLine() , and you'll be able to see the desired output in the Debug window.

     [TestMethod] public bool TestMetho() { var SY = calc.GetUserInfo(new DateTime(2015, 12, 15)); bool isOK = Assert.AreEqual(new DateTime(2015, 11, 29), SY); Debug.WriteLine("Date Time : {0}", SY) return bool; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM