I have a solution in visual studio with 2 projects. A normal one and a 'test' project for NUnit tests. I have a reference in the testing project to the normal project. I tried adding tests and running them with the NUnit GUI, but I get an error saying it can't find the 'dll' of the 'normal' project (I guess to get at the methods?). The thing is, the 'normal' project is not a class library, its an executable so the bin/Debug of the test project has normalproject.exe instead of normalproject.dll.
How can I get NUnit to work with this setup? I'd even be appreciative of a link to a tutorial that has this sort of setup, google searches so far hasn't turned up anything.
The Actual error code I'm getting is:
Achievement.Tests.Achievement.BruiserTest.CheckNameAndDescription: System.BadImageFormatException : Could not load file or assembly 'Achievement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
I had the same problem!
Solution:
NUnit installs with a x86 and a x64 binary. In the start menu it only shows the default x64 program.
My project is targeted to x86 due to some native libraries i use, so i had to manually start nunit-x86.exe
from C:\Program Files (x86)\NUnit 2.6.3\bin
and it worked!
Check is the accessibility of the classes you want to test. They have to be marked as public otherwise your test project won't be able to see them to load them up.
Another alternative to making your classes public is to use the InternalsVisibleTo attribute in your EXE and grant access to your test project DLL. Instead of public, you would just need to mark them as internal.
In the EXE's AssemblyInfo.cs:
[assembly: InternalsVisibleTo( "Project.Tests" )]
There is no problem referencing an EXE instead of a DLL for your tests (technically speaking anyways; app architecture is another matter)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With