C# 找不到类型或命名空间名称“NUnit”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9884015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 11:03:53  来源:igfitidea点击:

The type or namespace name 'NUnit' could not be found

c#frameworksselenium

提问by Ranadheer Reddy

I have a c# code.(which is exported from selenium IDE)

我有 ac# 代码。(从 selenium IDE 导出)

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace SeleniumTests
{
[TestFixture]
public class csharp
{
private ISelenium selenium;
private StringBuilder verificationErrors;

[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost:1924/");
selenium.Start();
verificationErrors = new StringBuilder();
}

[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop(); 
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}

[Test]
public void TheCsharpTest()
{
        selenium.Open("/cookie/Default.aspx");
        selenium.Type("id=TextBox1", "ranadheer");
        selenium.Type("id=TextBox2", "SE");
        selenium.Type("id=TextBox3", "hyderabad");
        selenium.Click("id=Button1");
        selenium.WaitForPageToLoad("30000");
        selenium.Click("id=Button2");
        selenium.WaitForPageToLoad("30000"); 
}
}
}

I pasted this code in a console application (visual studio 2008).
After running, I got this errors:

我将此代码粘贴到控制台应用程序(visual studio 2008)中。
运行后,我收到此错误:

The type or namespace name 'NUnit' could not be found.
The type or namespace name 'TestFixture' could not be found
The type or namespace name 'ISelenium' could not be found
The type or namespace name 'SetUpAttribute' could not be found

找不到类型或命名空间名称“NUnit”。
找不到类型或命名空间名称“TestFixture” 找不到
类型或命名空间名称“ISelenium” 找不到
类型或命名空间名称“SetUpAttribute”

What framework should I add to correct this errors?

我应该添加什么框架来纠正这个错误?

采纳答案by Dmitry Reznik

It seems like you have references missing. From official Selenium docs page:

似乎您缺少参考资料。从官方硒文档页面

Add references to the following DLLs: nmock.dll, nunit.core.dll, nunit. framework.dll, ThoughtWorks.Selenium.Core.dll, ThoughtWorks.Selenium.IntegrationTests.dll and ThoughtWorks.Selenium.UnitTests.dll

添加对以下 DLL 的引用:nmock.dll、nunit.core.dll、nunit。framework.dll、ThoughtWorks.Selenium.Core.dll、ThoughtWorks.Selenium.IntegrationTests.dll 和 ThoughtWorks.Selenium.UnitTests.dll

For your current problem, you need to reference at least NUnit.Framework.dll and Selenium dlls.

对于您当前的问题,您至少需要引用 NUnit.Framework.dll 和 Selenium dll。

Please read the docs page for more info.

请阅读文档页面了解更多信息。

回答by TGH

You need to add a reference to the NUNIT dll

您需要添加对 NUNIT dll 的引用

回答by Andrew

Right click on references in the solution explorer and click add reference. You will need to browse for the nunit.framework.dll

右键单击解决方案资源管理器中的引用,然后单击添加引用。您需要浏览 nunit.framework.dll