Skip to content

Instantly share code, notes, and snippets.

@yakreved
Created December 23, 2013 02:09
Show Gist options
  • Save yakreved/8090880 to your computer and use it in GitHub Desktop.
Save yakreved/8090880 to your computer and use it in GitHub Desktop.
unit test unity3d move object test
//тестируемый скрипт
using UnityEngine;
using System.Collections;
public class move : MonoBehaviour {
// Use this for initialization
void Start () {
}
public void MoveBoxZ ()
{
transform.position = new Vector3 (transform.position.x, transform.position.y, transform.position.z + 1);
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.UpArrow))
{
MoveBoxZ ();
}
}
}
//сам тест
using System;
using System.Threading;
using NUnit.Framework;
using UnityEngine;
namespace UnityTest
{
internal class MyTest
{
[Test]
public void ExceptionTest ()
{
throw new Exception ("Exception throwing test");
}
[Test]
public void moveTest ()
{
var box = GameObject.CreatePrimitive (PrimitiveType.Cube);
box.AddComponent<move> ();
var move = box.GetComponent<move>();
if(move == null)
throw new Exception ("test component is null(");
Vector3 old = move.transform.position;
move.MoveBoxZ ();
Assert.AreEqual (old, new Vector3 (move.transform.position.x, move.transform.position.y, move.transform.position.z - 1));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment