运行 NUnit 以编程方式进行测试[找不到参考]

Running NUnit tests programatically [Could not find reference]

我正在尝试 运行 通过 .NET Framework 控制台应用程序从 .txt 文件测试 WebDriver + NUnit,这是我的演示代码:

class Program
{
    static void Main(string[] args)
    {
        string source = File.ReadAllText(@"C:\Users\user\Desktop\SomeTest.txt");

        Dictionary<string, string> providerOptions = new Dictionary<string, string>
        {
            {"CompilerVersion", "v4.0"}
        };
        CSharpCodeProvider provider = new CSharpCodeProvider(providerOptions);

        CompilerParameters compilerParams = new CompilerParameters
        {
            GenerateInMemory = false,
            GenerateExecutable = false,
        };

        compilerParams.ReferencedAssemblies.Add("nunit.framework.dll");
        compilerParams.ReferencedAssemblies.Add("System.dll");
        compilerParams.ReferencedAssemblies.Add("WebDriver.dll"); 
        compilerParams.ReferencedAssemblies.Add("nunit.core.interfaces.dll");
        compilerParams.ReferencedAssemblies.Add("nunit.core.dll");

        compilerParams.OutputAssembly = @"C:\Users\user\Desktop\test.dll";

        CompilerResults compileResults = provider.CompileAssemblyFromSource(compilerParams, source);

        var assembly = compileResults.CompiledAssembly;

        CoreExtensions.Host.InitializeService();
        SimpleTestRunner runner = new SimpleTestRunner();
        TestPackage package = new TestPackage(assembly.Location);
        if (runner.Load(package))
        {
            TestResult res = runner.Run(new NullListener(),
                TestFilter.Empty, false, LoggingThreshold.Off);
        }
    }

我最终遇到了这个错误:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified.

这是我的参考资料:

有人知道这里的问题是什么吗?

我发现了问题,这些引用的复制本地 属性 必须设置为 true。现在有效