简体   繁体   English

无法将dll的所有C#类文件放入nunit

[英]Unable to get all C# class files of dll into nunit

I have added a new class file into the project. 我已经在项目中添加了一个新的类文件。 And compiled it. 并编译它。 I got a successful build. 我的构建成功。 But when i am trying to run the same dll into NUnit i am not getting the newly added class file in NUnit. 但是,当我尝试在NUnit中运行相同的dll时,我没有在NUnit中获得新添加的类文件。

Ho to get this newly added class file into the NUnit? 如何将此新添加的类文件放入NUnit? I am running the test in NUnit with selenium webdriver. 我正在使用Selenium Webdriver在NUnit中运行测试。 using NUnit version 2.6 使用NUnit版本2.6

一种可能的原因是您可能没有在类名上添加[Test]属性。

Nunit documentation says the following regarding classes that are picked up for testing: Nunit文档说了以下有关要测试的类的信息:

TestFixtureAttribute (NUnit 2.0 / 2.5) TestFixtureAttribute(NUnit 2.0 / 2.5)

This is the attribute that marks a class that contains tests and, optionally, setup or teardown methods. 这是标记包含测试以及可选的设置或拆卸方法的类的属性。 NUnit 2.5 introduces parameterized and generic test fixtures - see below. NUnit 2.5引入了参数化和通用测试夹具-参见下文。

Most restrictions on a class that is used as a test fixture have now been eliminated. 现在已消除了对用作测试夹具的类的大多数限制。 As of NUnit 2.5.3, a test fixture class: 从NUnit 2.5.3开始,测试夹具类:

  • May be public, protected, private or internal. 可以是公开的,受保护的,私有的或内部的。
  • May be a static class in .NET 2.0 or later. 在.NET 2.0或更高版本中可能是静态类。
  • May be generic, so long as any type parameters are provided or can be inferred from the actual arguments. 只要提供了任何类型参数,或者可以从实际参数中推断出任何类型,它就可以是通用的。
  • May not be abstract - although the attribute may be applied to an abstract class intended to serve as a base class for test fixtures. 可能不是抽象的-尽管该属性可以应用于抽象类,该抽象类旨在用作测试夹具的基类。
  • If no arguments are provided with the TestFixtureAttribute, the class must have a default constructor. 如果TestFixtureAttribute没有提供任何参数,则该类必须具有默认构造函数。
  • If arguments are provided, they must match one of the constructors. 如果提供了参数,则它们必须与构造函数之一匹配。

If any of these restrictions are violated, the class is not runnable as a test and will display as an error. 如果违反了任何这些限制,则该类不能作为测试运行,并且将显示为错误。

It is advisable that the constructor not have any side effects, since NUnit may construct the object multiple times in the course of a session. 建议构造函数不要有任何副作用,因为NUnit可能在会话过程中多次构造对象。

Beginning with NUnit 2.5, the TestFixture attribute is optional for non-parameterized, non-generic fixtures . 从NUnit 2.5开始,TestFixture属性对于非参数化,非通用灯具是可选的 So long as the class contains at least one method marked with the Test, TestCase or TestCaseSource attribute, it will be treated as a test fixture. 只要该类包含至少一个标有Test,TestCase或TestCaseSource属性的方法,它将被视为测试夹具。

(emphasis mine) (强调我的)

I'd advise going through the list to check whether any of these restrictions are violated. 我建议您仔细检查一下清单,以检查是否违反了这些限制。 If not, your nunit runner may not be pointing at the latest version of your assembly, but this is heavily setup-dependent so it's harder to troubleshoot the problem. 如果不是,您的nunit运行器可能没有指向程序集的最新版本,但这在很大程度上取决于安装程序,因此很难解决问题。

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

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