Inheritance: MonoBehaviour
 public void AddSuite(UnityTest suite)
 {
     testSuites.Add(suite);
 }
 public void AddSuite(UnityTest suite)
 {
     testSuites.Add(suite);
 }
Exemple #3
0
    public IEnumerator TestAll()
    {
        Time.captureFramerate = captureFramerate;
        Instance = this;
        Type t = GetType();
        MethodInfo[] methods = t.GetMethods(BindingFlags.Public | BindingFlags.Instance);
        // TODO: Sanity check things.  Make sure the method has no params, isn't
        // generic, isn't abstract, etc.

        // Order is randomized to minimize the likelihood of tests winding up
        // being accidentally order-dependant.
        ArrayList methodsInRandomOrder = new ArrayList();
        foreach(MethodInfo m in methods)
          methodsInRandomOrder.Insert(Mathf.RoundToInt(UnityEngine.Random.Range(0, methodsInRandomOrder.Count)), m);

        int testMethods = 0;
        foreach(MethodInfo m in methodsInRandomOrder) {
          if(m.Name.StartsWith("Test") && (m.Name != "TestAll")) {
        testMethods++;
        ResetTestState(t, m);

        DoSetup();

        // ---------------------------------------------------------------------
        if(hasValue) {
          if(typeof(IEnumerator).IsAssignableFrom(m.ReturnType))
            yield return StartCoroutine(TestCoroutine(m));
          else if(typeof(void).IsAssignableFrom(m.ReturnType))
            yield return StartCoroutine(TestVanillaMethod(m));
          else
            _Fail("Test method " + m.Name + " must be a coroutine or return void.  Returns: " + m.ReturnType.Name);
        }
        // ---------------------------------------------------------------------

        CheckExceptions(m);

        // Want to break out BEFORE teardown to make debugging possible.
        if(breakOnFailure && !currentResult.Passed) {
          UnityEngine.Debug.Break();
          yield return 0;
        }

        DoTearDown();

        AccumulateStats();

        // Skip a frame inbetween tests to avoid clobbering one another.
        yield return 0;
          }
        }
    }