简体   繁体   English

Visual Studio 单元测试的输出

[英]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.我想知道是否可以从单元测试方法中返回某种值、bool、string 或 int。

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.是否有可能做这样的事情,因为此时我无法将Assert.AreEqual方法分配给某些输出变量。

You sure can.你肯定可以。

  1. Add a reference to System.Diagnostics .添加对System.Diagnostics的引用。
  2. Make sure you choose Debug when you go to run your test.确保在运行测试时选择“ Debug
  3. Use Debug.WriteLine() , and you'll be able to see the desired output in the Debug window.使用Debug.WriteLine() ,您将能够在Debug窗口中看到所需的输出。

     [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; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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