Unit testing NUnit3TestExecutor转换测试,但未运行这些测试

Unit testing NUnit3TestExecutor转换测试,但未运行这些测试,unit-testing,nunit,console-application,nunit-3.0,Unit Testing,Nunit,Console Application,Nunit 3.0,试图让我的单元测试运行,但在单击“运行测试”之后,我在输出中只得到了“NUnit3TestExecutor转换了1个NUnit测试用例中的1个”。测试试图运行,但最终永远加载,直到我不得不手动取消该过程。你知道这是什么原因吗 using NUnit.Framework; using CalculatorApp; using System.IO; using System; using NUnit; namespace Tests {

试图让我的单元测试运行,但在单击“运行测试”之后,我在输出中只得到了“NUnit3TestExecutor转换了1个NUnit测试用例中的1个”。测试试图运行,但最终永远加载,直到我不得不手动取消该过程。你知道这是什么原因吗

using NUnit.Framework;
    using CalculatorApp;
    using System.IO;
    using System;
    using NUnit;



    namespace Tests
    {
        public class Tests
        {
            [SetUp]
            public void Setup()
            {
            }

            [Test]
            public void Test1()
            {

                using (StringWriter sw = new StringWriter())
                {
                    Console.SetOut(sw);
                    CalculatorApp.Program.Input1();
                    string expected = string.Format("Type a number, and then press Enter", Environment.NewLine);
                    Assert.AreEqual(expected, sw.ToString());
                    sw.Close();
                }
            }
        }
    }

根据您对控制台的使用情况,我假设您正在测试一个控制台程序。我还假设它等待用户的输入

不幸的是,它没有从代码中获得任何输入,因此挂起

通过驱动控制台应用程序的输入和输出来测试它是可能的,但很复杂。您通常需要在单独的过程中启动它,监视标准输出和错误输出,并驱动输入。大多数人不会用这种方式进行测试——至少那些有单元测试经验的人不会

更好的方法是测试进行计算的后端

还有一个我应该提到的复杂问题。。。NUnit本身控制控制台输出。因此,您的测试需要保存当前的输出设置,并在退出之前将其还原-否则,NUnit的继续处理将中断