简体   繁体   English

NUnit - 设置、测试和拆卸 - 未调用

[英]NUnit - SetUp, Test and TearDown - Not invoked

I'm trying to do Selenium webdriver test automation through C#.我正在尝试通过 C# 进行 Selenium webdriver 测试自动化。 I wanted to basically understand how NUnit works.我想基本上了解 NUnit 的工作原理。 I've the following code in VS我在 VS 中有以下代码

namespace SeleniumCHash
    {
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using System;
    using NUnit.Framework;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    [TestFixture]
    public class StartUpClassCopy
    {

        [SetUp]
        public void Initialize() {
            Console.WriteLine("hi");
        }

        [Test]
        public void LoginCheckCopy()
        {
            Console.WriteLine("hiTest");
        }

        [TearDown]
        public void EndTest()
        {
            Console.WriteLine("hiTear");
        }


    }
}

When I execute this through Test Explorer, the following is the output.当我通过测试资源管理器执行此操作时,以下是输出。

[12/4/2018 7:12:46 AM Informational] ------ Discover test started ------
[12/4/2018 7:12:49 AM Warning] No test is available in C:\Users\XXXX\Source\Repos\SeleniumCHash\SeleniumCHash\SeleniumCHash.csproj. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[12/4/2018 7:12:49 AM Informational] ========== Discover test finished: 0 found (0:00:03.4464214) ==========
[12/4/2018 7:13:04 AM Informational] ------ Run test started ------
[12/4/2018 7:13:05 AM Informational] NUnit Adapter 3.11.2.0: Test execution started
[12/4/2018 7:13:05 AM Informational] Running selected tests in C:\Users\XXXX\Source\Repos\SeleniumCHash\SeleniumCHash\bin\Debug\SeleniumCHash.exe
[12/4/2018 7:13:06 AM Informational]    NUnit3TestExecutor converted 2 of 2 NUnit test cases
[12/4/2018 7:13:06 AM Informational] NUnit Adapter 3.11.2.0: Test execution complete
[12/4/2018 7:13:06 AM Informational] ========== Run test finished: 1 run (0:00:02.0547664) ==========

I'm actually expecting the console to display this in the console.我实际上希望控制台在控制台中显示它。

hi
hiTest
hiTear

The Visual Studio output window is not the console. Visual Studio 输出窗口不是控制台。 :-) In fact, running under Test Explorer, there is no console available. :-) 事实上,在测试资源管理器下运行,没有可用的控制台。

NUnit, however, captures output directed to the console and does its own thing with it, saving it as part of the test result.然而,NUnit 捕获定向到控制台的输出并用它做自己的事情,将其保存为测试结果的一部分。 That result is made available to the runner as well, which can also do its own thing.该结果也可提供给跑步者,跑步者也可以做自己的事情。

In the case of the NUnit 3 VS adapter, what it does is add the text output to the test result displayed in Test Explorer.在 NUnit 3 VS 适配器的情况下,它所做的是将文本输出添加到测试资源管理器中显示的测试结果中。 It's visible in the IDE if you select the test that was run.如果您选择运行的测试,它在 IDE 中可见。 Below the tree of tests, you'll see the result, including the text output.在测试树下方,您将看到结果,包括文本输出。

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

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