NUnit.core is missing when I try to run tests programmatically?

868 views
Skip to first unread message

Brenda Chang

unread,
Jan 31, 2017, 6:58:50 PM1/31/17
to NUnit-Discuss
I have a use case where I need to be able to run Nunit tests programatically. I am currently using Nunit 2.6.3, and have NUnit Runners 2.6.3 and NUnitTestAdaptor 2.0.0 (highest version available) installed via NuGet in Visual Studio 15.

Anyways, when I run my tests using Test Explorer and via right clicking and selecting Run Unit Tests, everything is fine. No missing files, and the tests run successfully.

In my Main method, I have the lines

CoreExtensions.Host.InitializeService();
SimpleTestRunner runner = new SimpleTestRunner();

That's it. However, when I build and run, I immediately get the following exception:

Could not load file or assembly 'nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1ev7f44a77' or one of its dependencies. The system cannot find the file specified'.
I am referencing Nunit.core, nunit.core.interfaces, and nunit.framework.

Thank you for the help, and let me know if I need to provide any more details.

Charlie Poole

unread,
Jan 31, 2017, 7:15:57 PM1/31/17
to NUnit-Discuss
Hi Brenda,

Is there a reason you are using the NUnit adapter? Generally, when
working on NUnit itself, we avoid the adapter. That's probably a good
idea for anyone wanting to run NUnit programmatically as well, unless
you are making a super-adapter on top of ours.

If your code compiles, that means all the referenced assemblies are
found at compile-time. You have to also ensure they are available at
run time. How are your directories set up and where are the various
assemblies you are referencing?

Charlie
> --
> 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.

Brenda Chang

unread,
Feb 1, 2017, 9:09:37 AM2/1/17
to NUnit-Discuss
Hi Charlie,

Thank you for the response! I'm using the NUnit adapter as I was under the impression that nunit.core was only accessible via it, and it seems like for NUnit 2.6.3, nunit.core is needed to run NUnit programmatically. Let me know if I'm wrong though; I was running off of the information in this Stack Overflow link and also this one.

My directories are set up like so: 
  • ConsoleApp
    • Tests
      • References
        • CommandLine
        • log4net
        • nunit.core
        • nunit.core.interfaces
        • nunit.framework
        • nunit.util
        • NUnit.VisualStudio.TestAdapter
        • System
        • System.ComponentModel.DataAnnotations
      • Test1.cs
    • MainConsole
      • References
        • CommandLine
        • log4net
        • Microsoft.C.Sharp
        • MoreLinq
        • nunit.core
        • nunit.core.interfaces
        • nunit.framework
        • nunit.util
        • NUnit.VisualStudio.TestAdapter
        • System
        • System.ComponentModel.DataAnnotation
        • System.Configuration
        • System.Core
        • System.Data
        • System.Data.DataSetExtensions
        • System.Web.Extensions
        • System.Xml
        • System.Xml.Linq
      • MainConsole.cs
Where MainConsole.cs has the main method. My output directory is ConsoleApp/Output/MainConsole. I checked in there and it has nunit.framework, but not nunit.core; is it supposed to have nunit.core within the output directory? Thank you for all the help!!

Brenda

Charlie Poole

unread,
Feb 1, 2017, 8:46:41 PM2/1/17
to NUnit-Discuss
Looking more closely, your error message says it can't find nunit.core
2.6.4, while you indicated you were using nunit 2.6.3. Make sure there
is not a conflict.

The best ways to get the assemblies you need from NUnit V2 is to
either (1) install the msi or (2) download the zip. Use the msi if you
actually want a full install of NUnit on your machine. Otherwise, use
the zip as the place where you get a matched set of assemblies. The
NUnit VS adapter includes the two assemblies you are using, but if you
are not using the adapter, then there is no reason to download it.

Your runner should reference nunit.core.dll and
nunit.core.interfaces.dll. That's sufficient if you don't want to run
tests in a separate appdomain or process. Use the RemoteTestRunner by
preference. Advice to use the SimpleTestRunner that you find online
probably goes back to a toy app I posted many years ago. It's
surprising how such things spread!

Things you are currently referencing that you don't need:
* nunit.util - only if you are using something from it
* nunit.framework - should be referenced by your tests and never by the runner
* NUnit.VisualStudio.TestAdapter - has no relation to this at all

Good luck! Let me know if you have more questions. Also, be sure you
really need to do all this, rather than simply running NUnit. :-)

Charlie
Reply all
Reply to author
Forward
0 new messages