tags:

views:

1064

answers:

3

I am learning how to use NUnit. I have my main project in it's solution, and created a separate project in that same solution which will hold my unit tests, with it's own namespace. From that project I add a reference to the main project and add a

using MainProjectNamespace;

to the top of it.

When I go to NUnit, any tests I have that don't reference the main project work. These are tests I setup just to get used to NUnit, and are pretty much useless. When NUnit runs the real tests the test throws this exception:

TestLibrary.Test.TestMainProject: System.IO.FileNotFoundException : Could not load file or assembly 'WpfApplication2, Version = 1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the specified file.

Why am I getting this exception?

EDIT:

Now when I try to load the assembly into NUnit, it won't even load (so I can't even get a chance to run the tests)

This is the Exception that come sup, and the stack trace:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'LONG PATH HERE I DON'T WANT TO TYPE'

System.IO.DirectoryNotFoundException...

Server stack trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Directory.SetCurrentDirectory(String path) at NUnit.Core.DirectorySwapper..ctor(String directoryName) at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path) at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites) at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites) at NUnit.Core.TestSuiteBuilder.Build(TestPackage package) at NUnit.Core.SimpleTestRunner.Load(TestPackage package) at NUnit.Core.ProxyTestRunner.Load(TestPackage package) at NUnit.Core.ProxyTestRunner.Load(TestPackage package) at NUnit.Core.RemoteTestRunner.Load(TestPackage package) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

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.Core.TestRunner.Load(TestPackage package) at NUnit.Util.TestDomain.Load(TestPackage package) at NUnit.Util.TestLoader.LoadTest(String testName)

EDIT2: The above path clearly IS in my hard drive

EDIT3: I just switched from Debug to Release, on NUnit, and loaded the dll from the release folder of TestingLibrary... And it loaded! 1 of the 3 namespace-specific tests worked. Getting somewhere, I am.

EDIT4: Welllllllll... I can actually run the tests now, but I am back to the original error. IT is not finding the assembly for the main project

+1  A: 

The compiler removes all unused references, and doesn't deploy the dll unnecessarily. A using (by itself) does not count as a use. Either mark the dll for deployment via the "Copy to output directory" setting, or add some code that really uses types declared in the dll.

Marc Gravell
I have some code in there that creates a new instance of a class and does a few things. But the error still comes up.
Alex Baranosky
Also, the "Copy Local" property is set, which indicates whether the reference will be copied to the output directory.
Alex Baranosky
Marc, check your new comments. I can't get this thing to work, and you always have all the answers...
Alex Baranosky
Not all the time, I don't - sorry. The only other thought I have at the moment is "something to do with the SNK"... is anything strong-named?
Marc Gravell
in the Test class most of the references are Strong Named, the only one that isn't is the reference to the main project
Alex Baranosky
A: 

Did you rename the name of the output assembly OR namespace in the source project?

Looks like your source file is "WPFApplication1" & I am speculating that you might have changed the output type from dll to exe?

shahkalpesh
I did rename a few things when I was creating the original project, perhaps this messed something up? The new project's intellisense can figure out the types of my custom class objects, but for some reason itis causing trouble...
Alex Baranosky
I renamed the namespace for sure.
Alex Baranosky
shahkalpesh
you mean delete the reference to the original project from the testing project?
Alex Baranosky
I did the above, and rebuilt the original project, then added a reference to the testing project, and rebuilt it as well, still getting the same error
Alex Baranosky
Create a new test project. I think that will save you some time.
shahkalpesh
none of the details of the original project have changed since creating the Testing project
Alex Baranosky
I just made a new project, and now when I got o load the dll in NUnit it won't even let me load it. It gives me the same error as I was getting when running the tests except I am getting it when NUnit tries to load the assembly.
Alex Baranosky
wait, the above statement is false, actually I am getting s SIMILAR meesage but this time it can't find the NUnit framework dll
Alex Baranosky
Add a reference to Nunit.framework.dll now
shahkalpesh
yep, already did that
Alex Baranosky
shahkalpesh
A: 

It looks like one of the assemblies you are referencing in your app has dependencies on another assembly which is not in your bin folder.

RKitson
Thank you for your answer. I just checked my bin folder and both the debug and release subfolders contain all of the files that my TestLibrary depends on. Such as WpfApplication2.exe... Any other ideas?
Alex Baranosky
Are you trying to use the NUnit console App? If so, have you tried TestDriven.net? I was getting a similar error a few weeks ago, but it was because I was using a few different open source projects that all depended upon another project, but different versions.
RKitson
Does TestDriven.NET work with VS Express? I am not seeing the "Run Tests"
Alex Baranosky