|
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 !
(comments are locked)
|
|
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. @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)
|
|
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.
(comments are locked)
|
|
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/”.
(comments are locked)
|
Unity Answers has moved to a new system, and some users may have trouble logging in.