异常:无法将类型为“NUnit.Core.NamespaceSuite”的对象强制转换为“NUnit.Core.TestFixture”

时间:2018-02-22 12:35:45

标签: c# nunit-2.6

我在执行以下代码时遇到了类型转换异常:

public static void Main(String[] args)
{            
    string testpackagepath = @"C:\Users\pjena\source\repos\Lacerte.Test\Lacerte.Test.Nunit\bin\Debug\Lacerte.Test.Nunit.dll";

    CoreExtensions.Host.InitializeService();
    TestSuiteBuilder builder = new TestSuiteBuilder();
    TestPackage testPackage = new TestPackage(testpackagepath);
    RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
    remoteTestRunner.Load(testPackage);

    TestSuite suite = builder.Build(testPackage);
    TestSuite test = suite.Tests[0] as TestSuite;
    var numberOfTests = ((TestFixture)test.Tests[0]).TestCount;

    foreach (TestMethod t in ((TestFixture)test.Tests[0]).Tests)
    {
        Console.WriteLine(t.TestName.Name);
    }

    TestName testName = ((TestMethod)((TestFixture)test.Tests[0]).Tests[0]).TestName;
    TestFilter filter = new NameFilter(testName);
    TestResult result = test.Run(new NullListener(), filter);
    ResultSummarizer summ = new ResultSummarizer(result);
    Assert.AreEqual(1, summ.ResultCount);
}

我收到错误:

  

“无法转换类型的对象   'NUnit.Core.NamespaceSuite'键入'NUnit.Core.TestFixture'。“

我在这个论坛上尝试了一个答案,并陷入了这个问题Nunit-C#: run specific Tests through coding

0 个答案:

没有答案