SharpUnit

From Unify Community Wiki
Jump to: navigation, search

SharpUnit is a unit testing framework written in C# specifically for Unity3D. It was inspired by and adapted from UUnit, which is written in Boo. It is my hope that SharpUnit will help Unity3D developers write and maintain solid code. Enjoy!

Mark Gants | mgants[at]bigpoint[dot]net

Contents

Get SharpUnit

SharpUnit has been added to GitHub (finally!). Get it here:

Each version of SharpUnit has been committed sequentially to GitHub to maintain the revision history. Feel free to contribute improvements.

Why SharpUnit?

  • Because NUnit is not so easy to integrate into Unity3D.
  • UUnit works but, while I personally like Boo, not everyone is familiar/comfortable with programming in Boo.
  • SharpUnit allows you to trap/expect exceptions, UUnit does not (as of May 20, 2010).
  • SharpUnit can easily be integrated into Unity3D but is not dependant on the Unity3DEngine namespace.
  • SharpUnit can easily extended and tested outside of Unity3D and even be used for other purposes.
  • SharpUnit is straight-forward and easy to use.

Getting Started:

  • The Visual Studio solution contains two projects: SharpUnit and SharpUnitTest
    • SharpUnit: This is the class library that can be built to a DLL.
    • SharpUnitTest: This is a console app that runs the unit tests for SharpUnit itself.
  • The Main() function in Program.cs is an example test runner, it illustrates how to get up and running with SharpUnit.
  • The Unity3D_SharpUnitDemo.zip file contains an actual Unity3D 2.6 project using SharpUnit.

Integrate with Unity3D Using a DLL:

  1. Build the SharpUnit.dll from source using Visual Studio.
  2. Create a folder named "SharpUnit" In your Unity3D project's "Assets" folder.
  3. Place the SharpUnit.dll in this folder.
  4. Copy the Unity3D_TestRunner.cs and Unity3D_TestReporter.cs files to this folder.

Integrate with Unity3D Using the Scripts:

  1. Create a folder named "SharpUnit" In your Unity3D project's "Assets" folder.
  2. Copy the SharpUnit class files (*.cs) to this folder.
  3. Copy the Unity3D_TestRunner.cs and Unity3D_TestReporter.cs files to this folder.

Running Tests in Unity3D:

  1. Create an empty GameObject within Unity, name it TestRunner.
  2. Drag the Unity3D_TestRunner.cs script onto the TestRunner game object.
  3. Write unit test scripts as classes derived from the TestCase class.
  4. Configure the TestSuite object in the Unity3D_TestRunner.cs script to run your tests.
  5. Press Play, you should see the test output in the Unity3D editor console.

Extending SharpUnit:

  • Derive a new class from TestReporter to modify how SharpUnit reports test results and errors.
  • Feel free to extend this project any way you like. I have no problems if someone wants to host it somewhere and continue developing on it. Just respect the terms of the original license included with the project and make your improvements available to the rest of the Unity3D community.
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox