繁体   English   中英

为什么要面对“找不到类型或名称空间名称'UnitTestClassBase'(您是否缺少using指令或程序集引用?)”?

[英]Why am I facing “The type or namespace name 'UnitTestClassBase' could not be found (are you missing a using directive or an assembly reference?)”?

我正在使用Testleft自动执行测试方案。

第一次使用VS。

这是代码:

############################################################################
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using System.Text;
using SmartBear.TestLeft;
using SmartBear.TestLeft.TestObjects;
using SmartBear.TestLeft.TestObjects.Win;
using System.IO;

namespace TestLeftProject1
{
    [TestClass]
    public class TestLeftTest : UnitTestClassBase
    {
        #region Class initializers
        [ClassInitialize]
        public static void ClassInitialize(TestContext context)
        {
            UnitTestClassBase.InitializeClass(context);
        }

        [ClassCleanup]
        public static void ClassCleanUp()
        {
            UnitTestClassBase.FinalizeClass();
        }
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            // Runs the Notepad application
            IProcess process = Driver.Applications.Run("notepad.exe");

            // Gets Notepad's edit box
            IWinTextEdit edit = process.Find<ITopLevelWindow>(new WindowPattern()
            {
                WndClass = "Notepad"
            }).Find<IWinTextEdit>(new WindowPattern()
            {
                WndClass = "Edit"
            });

            // Simulates a mouse click in Notepad
            edit.Click();

            // Simulates text input in Notepad
            string inputText = "test";
            edit.SetText(inputText);

            // Verifies the text that Notepad contains
            Assert.AreEqual(inputText, edit.wText);

            // Posts messages to the TestLeft test log
            Driver.Log.Screenshot(edit, "Notepad's edit box screenshot");
            Driver.Log.Warning("A warning message");

            // Saves the TestLeft test log
            string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), DateTime.Now.ToString("MM_dd_yyyy_H_mm_ss"));
            Driver.Log.Save(logPath, Log.Format.Html);
        }
    }
}

我尝试了其他解决方案,例如将目标框架从4.5更改为4和4.5.1。

我不确定该怎么办。 我是VS的新手。 请帮忙

您需要添加一个名称为UnitTestClassBase的类。

无论如何,看看如何编写好的单元测试。 您还应该使用Arrange, Act and Assert

您很可能缺少对程序集SmartBear的引用。 要验证这一点,请转到解决方案资源管理器中的参考,并检查是否引用了该程序集。 如果不是,请将其添加为参考。

暂无
暂无

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

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