简体   繁体   中英

NUnit: is it possible to reference classes from my application?

I recently ran into a brick wall with Visual Studio 2008's testing framework: testing 64 bit dlls is not possible with VS 2008 . I have a project that compiles to x64 only and I need to create some unit tests for the project and I can't use the VS2008 testing framework to do it.

Subsequently, I downloaded the latest NUnit framework (which as far as I understand supports x64 testing), but now I'm trying to duplicate the same behavior that Visual Studio had with its testing framework. Namely, I would like to instantiate classes within the text fixture that are defined in my project.

Here is an example:

  • I have a project (call it MyProject) that compiles to an executable: MyProject.exe
  • There is a class within MyProject that's called MyClass .
  • I have a separate project for my tests, called MyProjectTest, and it compiles to a dll (so I can run it with NUnit).
  • How can I instantiate MyClass inside MyProjectTest?

As far as I understand NUnit seems to be designed for testing DLLs not EXEs, so what do I have to do if I want to test classes within an EXE? Reflection? I assume that's how VS2008's testing framework gets access to the classes...

How can I instantiate MyClass inside MyProjectTest?

The normal way to do this is for your MyProjectTest project to contain a reference to MyProject

But it seems most people don't like the idea of referencing an exe and hence would have MyClass defined in a third dll which is referenced by both the MyProject and MyProjectTest

As far as I understand NUnit seems to be designed for testing DLLs not EXEs.

I must admit, all my tests are in dlls, but the default filespec for the Nunit Add assembly dialog box is *.dll and *.exe which would suggest otherwise.

An executable and a DLL are nearly identical. There are some differences, but none that should serve as a hindrance to referencing an executable from your NUnit test project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM