Inheritance: UnityEngine.MonoBehaviour, ITestCase
示例#1
0
    /**
     * Add all test cases to the test suite.
     *
     * @param test, the test case containing the tests we will add.
     */
    public void AddAll(UnityTestCase test)
    {
        // If test invalid
        if (null == test)
            {
                // Error
                throw new Exception("Invalid test case encountered.");
            }

        // For each method in the test case
        Type type = test.GetType();
        foreach (MethodInfo method in type.GetMethods())
            {
                // For each unit test attribute
                foreach (object obj in method.GetCustomAttributes(typeof(UnitTest), false))
                    {
                        // If attribute is valid
                        Attribute testAtt = obj as Attribute;
                        if (null != testAtt)
                            {
                                // create GameObject and attach
                                GameObject gameobj = new GameObject("Test" + type.Name + "_" + method.Name);
                                UnityTestCase tmp = gameobj.AddComponent(type.Name) as UnityTestCase;
                                tmp.SetTestMethod(method.Name);
                                m_tests.Add(tmp);
                            }
                    }
            }
    }