Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nunit - testing exe

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.

like image 516
will Avatar asked Feb 18 '23 22:02

will


2 Answers

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!

like image 85
JCH2k Avatar answered Mar 03 '23 17:03

JCH2k


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)

like image 45
Joe Doyle Avatar answered Mar 03 '23 18:03

Joe Doyle