Search Unity

Unit testing of code written for Unity

Discussion in 'Scripting' started by magwo, Jan 12, 2010.

  1. magwo

    magwo

    Joined:
    May 20, 2009
    Posts:
    402
    Is anyone doing unit testing with Unity code? I'd like to do it, but I just see lots of problems with it due to all the global state.. for example:

    * Current scene, as loaded through the globally available Application static members. Lots of ways everywhere to access this global state (FindObjectsOfType etc, even static methods).
    * Static accessors for Camera, Terrain, etc.
    * Physics state, "transitively" available through static methods in Physics class.


    Anyone that can give some hints on how to do reasonable amounts of unit testing, while not losing the productivity of Unity completely?

    It's a bit weird really. I really like the idea of unit testing and reusable code... but people still churn out excellent Unity products that (I assume) have completely untestable (automated testing-wise) code. So are unit tests overkill for Unity game code?

    Can't really make up my mind. How do you see it? Can unit testing and Unity be friends?
     
  2. magwo

    magwo

    Joined:
    May 20, 2009
    Posts:
    402
    BTW, found some stuff like this while searching:
    http://forum.unity3d.com/viewtopic.php?t=38078

    But it doesn't really address the issue of Unity's massive global state clashing with the opportunity to instantiate a small portion of your application, and run it isolated.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    the only way to do that would be isolated test scenes basically
     
  4. mgants4

    mgants4

    Joined:
    Jun 3, 2010
    Posts:
    1
  5. Ryuuguu

    Ryuuguu

    Joined:
    Apr 14, 2007
    Posts:
    391
    Does this work with MonoDev, I'm on a Mac don't really want to use a virtual machine anymore to get Visual Studio.

    On thinking this through I realize at least the basic in unity stuff will work for sure if there is a dll included in the package, which there is.
     
    Last edited: Dec 30, 2010
  6. mindlace

    mindlace

    Joined:
    Mar 31, 2007
    Posts:
    24
    I tried SharpUnit and the other stuff on this subject but nothing really worked for me. SharpUnit is cool but I didn't want so much stuff written to the console, and I wanted to be able to test multiple scenes etc...

    So we wrote TestStar. It might be interesting if you want to try doing more testing. You can also watch an <5min video showing off some of the cool things it does.