UUnit

EDIT:I am updating the wiki page it also has the latest version.

I put this in the Wiki but could not find a place to uplaod packages so I am also posting with attachment here.

UUnit is a simple xUnit style Framework for unit testing inside Unity IDE. NUnit is desegnined to be called from the console or run on a windows GUI. NUnitLite is designed for IDEs like Unity but is not incluced in the Unity Package so to be run easily and portably between projects it needs to included in assests. Unfortunately NUnitlite does not put each class in a file of the same name so Unity will not load the files.

So here is UUnit (version 0.2 as of 2007/08 ). To run its own tests attach “RunnerTestCase” to an object and it’s start method will run the test cases on UUnit. Output goes to Debug.Log. To make your own test cases use “TestCaseTest” as exmple. the “[Test]” attribute marks tests and if the class is added to the suite all methods with a Void return and no paramaters signature will be run.example runner code is below.

		suite = TestSuite()  #create a test suite
		suite.AddAll(TestCaseTest()) #AddAll [Test] methods in TestCaseTest
		result = suite.Run(null) # run all tests
		Debug.Log(result.Summary()) #send results to Debug.Log

45550–1651–$uunit_182.unitypackage (5.84 KB)

I have updated UUnit with some changes, and hopefully made it a bit easier for new users to understand and implement. VERY little code has changed, it’s documented on the wiki:

Hello,

I ported UUnit to C# and put it on a SVN repo. Check it at:

http://code.google.com/p/uunit/

[ ]'s,

Hooray!

Sadist! :wink:

In fact NUnit and/or NUnitLite should work fine inside Unity, you just need to provide a frontend that finds tests to run, submits them, and communicates the results. We played with it a bit last year at work.

But the difficult question ends up being, what do you actually want to test? If it’s not Unity-dependent then you’re probably better off testing within the IDE, e.g. using Resharper’s excellent test management features to drive NUnitLite. However, even for non-Unity code it can still be useful to run tests on the target platform, so there is still value in providing xUnit test frameworks inside Unity.

If it is Unity-dependent then I don’t think xUnit is the right shape. It’s for unit testing, after all, and I think if you use much beyond the maths library then it doesn’t really count as “unit”. Functional testing has a different set of requirements.

Right now the frontend I’m building is a little bit entangled to my project. Once I manage to clean these dependencies up I intend to publish it there.

I agree with you. That is, in my opinion, the core question. As for myself, I’m using UUnit alone to do unit testing and UUnit, fixtures, builders and the edit-time environment to run my functional tests (that because I don’t know how to mock in Unity).

The sad part of this is that my code might have a lot of “hindenbugs”, since I ended up doing things like checking if I’m in editor or in play mode.

If I ever manage to decouple this from my project, I might publish it there as an extension to UUnit… sure, if anyone is interested.

[ ]',s