以NUnit.Console-3.8.0作为目标可执行文件运行dotcover会引发异常

时间:2019-01-08 07:14:31

标签: c# c#-4.0 nunit nunit-console dotcover

我正在尝试使用 NUnit.Console-3.9.0 \ nunit3-console-runner.exe 作为目标可执行文件来运行dotcover。

到目前为止,我的工作已附上代码和屏幕截图。

using System;

namespace secondApp
{
    public class Class1
    {
        public int add(int a, int b)
        {
            return a + b;
        }

        public int sub(int a, int b)
        {
            return a - b;
        }
    }
}

这是相应的测试文件。

using NUnit.Framework;
using secondApp;

namespace Tests
{ 
    public class Tests
    {
    private Class1 class1;
    [SetUp]
    public void Setup()
    {
        class1 = new Class1();
    }

    [Test]
    public void AddTest1()
    {
        int val = class1.add(1, 2);
        Assert.AreEqual(val, 3);
    }

    [Test]
    public void SubTest()
    {
        int val = class1.sub(1, 2);
        Assert.AreEqual(val, -1);
    }
}
}

这是file_coverage.xml文件(dotcover c file_coverage.xml),这是发生错误的地方

<?xml version="1.0" encoding="utf-8"?>
<AnalyseParams>
  <TargetExecutable>..\3rdparty\NUnit.Console-3.9.0\nunit3-console.exe 
  </TargetExecutable>
 <TargetArguments>.\Testfile.nunit</TargetArguments>
  <Output>output.dcvr</Output>
  <Filters>
    <IncludeFilters>
       <FilterEntry>
          <ModuleMask>*</ModuleMask>
           <ClassMask>*</ClassMask>
           <FunctionMask>*</FunctionMask>
       </FilterEntry>
    </IncludeFilters>
  </Filters>
</AnalyseParams>

这是Testfile.nunit

<NUnitProject>
  <Settings activeconfig="Debug" />
  <Config name="Debug" binpathtype="Auto">
  <assembly path=".\bin\Debug\netcoreapp2.1\Test.dll" /> 
  </Config>
</NUnitProject>

这是错误

dotcover c file_coverage.xml
JetBrains dotCover Console Runner 2018.2.3. Build 777.0.20180912.160624
Copyright (c) 2009-2019 JetBrains s.r.o. All rights reserved.
[JetBrains dotCover] Coverage session started [1/8/2019 12:19:36 PM]
NUnit Console Runner 3.8.0
Copyright (c) 2018 Charlie Poole, Rob Prouse

Runtime Environment
   OS Version: Microsoft Windows NT 10.0.16299.0
  CLR Version: 4.0.30319.42000

Test Files
    c:\rough-work\secondApp\Test\Testfile.nunit


Errors, Failures and Warnings

1) Error : c:\rough-work\secondApp\Test\Testfile.nunit
NUnit.Engine.NUnitEngineException : An exception occurred in the driver while loading tests.
  ----> System.IO.FileNotFoundException : Could not load file or assembly 'nunit.framework' or one of its dependencies. The system cannot find the file specified.
--NUnitEngineException

Server stack trace:
   at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
   at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
   at NUnit.Engine.Runners.TestDomainRunner.LoadPackage()
   at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
   at NUnit.Engine.Runners.DirectTestRunner.RunTests(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Runners.AbstractTestRunner.Run(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Agents.RemoteTestAgent.Run(ITestEventListener listener, TestFilter filter)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at NUnit.Engine.ITestEngineRunner.Run(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Runners.ProcessRunner.RunTests(ITestEventListener listener, TestFilter filter)
--FileNotFoundException
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
   at NUnit.Engine.Drivers.NUnit3FrameworkDriver.CreateObject(String typeName, Object[] args)
   at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
   at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)

Test Run Summary
  Overall result: Failed
  Test Count: 0, Passed: 0, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2019-01-08 06:49:38Z
    End time: 2019-01-08 06:49:38Z
    Duration: 0.603 seconds

Results (nunit3) saved as TestResult.xml
[JetBrains dotCover] Coverage session finished [1/8/2019 12:19:40 PM]
[JetBrains dotCover] Analyzed application exited with code '-100'
[JetBrains dotCover] Coverage results post-processing started [1/8/2019 12:19:40 PM]
[JetBrains dotCover] Coverage results post-processing finished [1/8/2019 12:19:40 PM]

2 个答案:

答案 0 :(得分:0)

您的异常日志显示找不到nunit.framework程序集,请检查其是否存在于引用中,如果存在,请转到工具->选项->测试并取消选中以下屏幕快照中突出显示的选项: enter image description here

让我知道是否有帮助。

答案 1 :(得分:0)

测试文件的路径表明它是一个.NET Core文件。目前无法从NUnit3-控制台运行程序执行.NET Core测试,而必须使用dotnet test