x


Is there a way to use Nunit with Unity in Monodevelop ?

I was pretty thrilled to see that Monodevelop came with a version of Nunit, however I've been hitting a wall, trying to unit-test my scripts...

I'm not sure how to go about this.

I've tried a few things, which were all dead ends, so I won't bother detailing them here.

However my approach was, mostly, trying to build a separate Nunit test project that'd use the UnityEngine dll, but that didn't work.

I'm thinking I should instead try using Nunit from within Unity, but couldn't figure it out so far...

I'm merely trying to find out if there is actually a way to test my unity-specific code using vanilla Nunit, and how I could go about that...

Will appreciate any insight.

Cheers !

more ▼

asked Mar 31 at 05:33 AM

julien\'s gravatar image

julien
88 4 6 11

(comments are locked)
10|3000 characters needed characters left
 moderation talk

6 answers:

You can use NUnit, just likely not to test code that directly depends on UnityEngine.dll - that dll is mostly a shell to act as an interface for the actual engine. You could consider running Unity as a headless server and communicate to it via an API of your own, testing the results of the operations, but that seems more trouble than it's worth.

The approach I use is to remove as much work as possible to classes that do not depend on UnityEngine at all, abstracting the actual system work. For instance, your AI can probably be implemented mostly independent of the engine's functions, with the colliders, raycasting and whatnot acting mostly as a sensory mechanism. You then write unit testing for these standalone classes, and use them on your MonoBehaviors as well.

more ▼

answered Mar 31 at 09:06 AM

Ricardo\'s gravatar image

Ricardo
4.7k 19 27 95

@Ricardo, could you expand on the steps needed? Although llavigne has a set of steps, I got errors trying to load irrelvnt.dll. Do I need to create a separate Namespace for my non-Monobehavior .cs files? Thanks.

Jul 25 at 08:43 PM Cyclops

That's a funny error (assuming that's the actual dll name and not some placeholder you typed). Namespaces are not an issue, so I'm a bit at a loss as to what might be going on. I simply have a separate test project, which I have to keep adding to the solution as Unity forgets it when recreating it, and which runs just fine from MonoDevelop. Can you give us more details Cyclops?

Jul 26 at 07:40 AM Ricardo

As llavigne mentioned, yes there actually is a irrelevant.dll in a side-directory which I tried adding to NUnit, but it was... irrelevant. What I did that worked was just copy my non-monobehavior scripts to a directory outside the Unity project, and using Visual Studio Express, create a new assembly/dll for NUnit. This certainly works, but means I have two copies of the script files in separate locations. I wasn't sure if there was some workflow that used only the one set of files, but didn't interfere with Unity's project. For instance (continued) -

Jul 26 at 01:37 PM Cyclops

For instance, can VS Express be told to create more than one assembly from a project, containing only the non-monobehavior files, in a different directory? Not sure if this is clear or not. :)

Jul 26 at 01:38 PM Cyclops

Ah, I see, you're using VS Express. I'm afraid I've only used this with Unity in MonoDevelop, and have used NUnit on a full VS version (but not for a Unity project). I didn't have to jump through as many hoops - I merely created an NUnit project for the solution and added a reference to the one with the main codebase. MonoDevelop supports NUnit projects natively. I'd recommend looking into the NUnit plugin that's floating around, but I don't believe VSExpress supports plugins.

Jul 26 at 02:25 PM Ricardo
(comments are locked)
10|3000 characters needed characters left
 moderation talk

I'm thinking your only nice option would be to have your unit test solution launch and build your project (via editor batch mode command-line parameters) and then run the built standalone - using Debug.Log and the log files for print/expect.

Listing your previous attempts is always a good idea though. Maybe you were onto something that just needs a bit of tweaking.

more ▼

answered Mar 31 at 09:12 AM

AngryAnt\'s gravatar image

Emil Johansen ♦♦
3.4k 10 15 50

(comments are locked)
10|3000 characters needed characters left
 moderation talk

this is what i found useful it allows you to use nUnit lite.

more ▼

answered Jul 10 at 05:17 PM

Ashkan\'s gravatar image

Ashkan Sa'eedi
7.9k 30 52 111

(comments are locked)
10|3000 characters needed characters left
 moderation talk

When working with NUnit in MonoDevelop, I ran into a bit of weirdness where rebuilds within Unity would delete MonoDevelop's reference to the nunit.framework dll. The eventual solution was to import the dll directly into the root of the Unity Assets folder. On Windows the dll was located at “Program Files (x86)/Unity/MonoDevelop/Addins/NUnit/”.

more ▼

answered Feb 20 at 06:52 AM

ljfranklin\'s gravatar image

ljfranklin
1

(comments are locked)
10|3000 characters needed characters left
 moderation talk

UnityCommunity has a page on using NUnit with Unity.

more ▼

answered Feb 16 at 09:46 AM

thomasw\'s gravatar image

thomasw
31 3 3 5

(comments are locked)
10|3000 characters needed characters left
 moderation talk
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x217
x31
x5
x5

Asked: Mar 31 at 05:33 AM

Seen: 2390 times

Last Updated: Mar 31 at 09:06 AM

powered by Qato - Enterprise Q&A