Problem integrating NUnit ot an existing C++/CLI project

404 views
Skip to first unread message

Nicholas Mario Wardhana

unread,
Sep 5, 2017, 12:10:48 PM9/5/17
to NUnit-Discuss
Hello everyone,

I am a new NUnit user and have been struggling to integrate it to our existing C++/CLI-based project. These are the steps that I have performed.
  1. As my first attempt of using NUnit, I downloaded the C++/CLI sample project from here: https://github.com/nunit/nunit-cpp-samples 
  2. I tried both a) opening the solution in that project, and b) created my own empty project, followed by adding the CPP file from that sample.
  3. I cannot install NUnit 3.8.1 via Nuget with the following message: “Could not install package 'NUnit 3.8.1'. You are trying to install this package into a project that targets 'native,Version=v0.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.” (I notice that this can be done on a separate C# project)
  4. I had to install NUnit manually (copy to a “packages” folder) and added a reference to nunit.framework.dll.
  5. The tests are detected in Test Explorer and I can run them. The following messages are shown in the Output window.

    [05/09/2017 11:52:18 Informational] ------ Run test started ------
    [05/09/2017 11:52:18 Informational] NUnit Adapter 3.8.0.0: Test execution started
    [05/09/2017 11:52:18 Informational] Running all tests in [path omitted]\TestNUnit-2.dll
    [05/09/2017 11:52:18 Informational] NUnit3TestExecutor converted 34 of 34 NUnit test cases
    [05/09/2017 11:52:18 Informational] NUnit Adapter 3.8.0.0: Test execution complete
    [05/09/2017 11:52:18 Informational] ========== Run test finished: 34 run (0:00:00.743933) ==========

  6. Now, I try to repeat steps 1-5 to our existing library solution. I created an empty C++/CLI project, and added the reference as well as the same CPP file. I can build the project, but no tests are detected. The message below is shown. 

    [05/09/2017 12:15:59 Informational] ------ Discover test started ------
    [05/09/2017 12:15:59 Informational] ========== Discover test finished: 0 found (0:00:00.0170448) ==========

    I suppose I have chosen the correct Default Processor Architecture (x86).

  7. I also tested the nunit3-console.exe and got the following messages for both files (the DLL produced by an independent project and another by a project in the existing solution).

    1) Error :

    An exception occurred in the driver while loading tests.

    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)

    Test Run Summary
      Overall result: Failed
      Test Count: 0, Passed: 0, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
      Start time: 2017-09-05 11:27:50Z
        End time: 2017-09-05 11:27:50Z
        Duration: 0.240 seconds

  8. However, I gave NUnit Gui a try and apparently the DLL produced by step number 5 does contain the test fixtures and cases.
So my questions are:
  1. At step number 3, is there another way to install NUnit via Nuget to a C++/CLI project?
  2. How can I detect if I have made a mistake/missed a step in running the test in point 6?
I use NUnit 3.8.1 and Visual Studio 2017 on Windows 10. Please let me know if more information is needed to solve this problem. Thank you.

Best regards,
Nicholas

Rob Prouse

unread,
Sep 14, 2017, 11:50:48 AM9/14/17
to NUnit-Discuss
As far as I know, C++/CLI still doesn't support NuGet packages so you are out of luck there. Adding the references manually is the solution I use too.

As for the error finding the tests, check your bin folder to make sure that all referenced assemblies are included. C++/CLI will copy in managed assemblies, but it doesn't copy in native assemblies. You will need a post build step to manually copy in the native DLLs and any other native artifacts that you might need.

Also, make sure that your test assembly targets the same architecture as the assemblies you are testing. I don't think that is the issue in this case because it usually causes a bad image format exception, but it is something to check.

--
You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nunit-discus...@googlegroups.com.
To post to this group, send email to nunit-...@googlegroups.com.
Visit this group at https://groups.google.com/group/nunit-discuss.
For more options, visit https://groups.google.com/d/optout.
--

Rob Prouse

Reply all
Reply to author
Forward
0 new messages