![](/img/trans.png)
[英]How to parameterized C# NUnit TestFixtures with multiple browsers
[英]Running TestFixtures from multiple class files in NUnit
我在C#中有一个简单的NUnit项目。 我有一个文件TestFixture.cs,可以成功运行其四个测试。 如果要在新的CS文件中添加其他测试,该怎么做? 如果仅将代码从TestFixture.cs复制到新的TestFixture2.cs中,并将TestFixture类分别重命名为TestFixture3和4,则它们将不会执行。 我认为它们会自动运行。 我是否需要告诉跑步者它是否是TestFixture.cs以外的文件? 这是我的代码:
namespace NUnitTest1
{
[TestFixture]
public class TestFixture3
{
[Test]
public void TestTrue()
{
Assert.IsTrue(true);
}
// This test fail for example, replace result or delete this test to see all tests pass
[Test]
public void TestFault()
{
Assert.IsTrue(true);
}
}
[TestFixture]
public class TestFixture4
{
[Test]
public void TestTrue()
{
Assert.IsTrue(true);
}
// This test fail for example, replace result or delete this test to see all tests pass
[Test]
public void TestFault()
{
Assert.IsTrue(true);
}
}
}
我的单元测试通过使用以下代码执行命令行程序来运行:
namespace NUnitTest1
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string[] my_args = { Assembly.GetExecutingAssembly().Location };
int returnCode = NUnit.ConsoleRunner.Runner.Main(my_args);
if (returnCode != 0)
Console.Beep();
}
}
}
当您加载NUnit时,NUnit会自动从测试程序集中获取所有带有TestFixture
属性标记的类型(无论夹具是位于一个.cs文件中还是位于单独的文件中)。 然后,NUnit将搜索标记有Test
或TestCase
属性的方法并加载它们。 如果NUnit没有看到任何测试,请确保已加载最新版本的测试程序集。
注意:如果您使用的是NUnit测试运行器,则有一个不错的设置, 当测试组件更改时,重新加载 。 启用此选项后,在Visual Studio中重建NUnit时,它将自动重新加载测试程序集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.