Unity3D TestTool Part _1

  一直想看看Unity3d官方推出的UnityTestTools的测试插件,今天有空尝试了一下。

 一、Quick Start

  1、 create a plane position which transform position is vector3 (0,0,0),attach a script name it hero.Content next:  

    public float Health = 100f;

    void OnCollisionEnter(Collision collision)
    {
        Health -= 10f;
        Destroy(collision.gameObject);
    }

  2、create a gameobject which transform position is vector3 (0,10,0), attach a script name it Spawn,Context next:

// Use this for initialization
	void Start () {
        InvokeRepeating("CreateRigidbody", 0f, 2f);
	}

    void CreateRigidbody() {
        GameObject tmp = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        //不加位置默认(0,0,0)
        tmp.transform.position = transform.position;
        tmp.AddComponent<Rigidbody>();
        
    }

  3. Attach Assertin Component Script,set like next

  

     4.Now,Run you sence. When you hero's Health below 50 , there is a AssertionException: FloatComparer assertion failed.

   从上述看,这个解决了一些我们在Unity主线程调用函数的时候的一些逻辑判断。这样我们就不用在自己嵌入代码了。缺点就是如果场景太多,这些Component我们又不想要了,就有点麻烦了。

二、Integration Test Runner

  1.Click Unity Test Tools -> Integration Test Runner. Click  Symbol '+' to create TestRunner.

      

  2.Let's do something. Create a Plane.you will find the plane auto be the child of New Test. Then Create a cube then attach component rigidbody.

  3.Last, you can attach  Call Testing Script ,Set Config like that .The config is means when the cube collide the plane ,the test runner suscess.

  

   4.可以测试在Unity主线程调用的一些函数。

 

 

posted @ 2014-09-17 21:17  灵魂重新  阅读(385)  评论(0编辑  收藏  举报