jeudi 18 juillet 2019

Unity3D Test Runner in PlayMode not providing test feedback

I just started using Unity to build up a flappy dinosaur game. Because I am developping my game following TDD philosophy, I want to have my game tested. Therefore, here's what I tried to do without success on Unity 2019.1.9.f2:

  1. Create new 2D project
  2. In the TestRunner, select PlayMode
  3. Create PlayMode Test Assembly Folder
  4. Create Test Script in current folder

Here's the test code I want to try:

using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace Tests
{
  public class NewTestScript
  {
    // A Test behaves as an ordinary method
    [Test]
    public void NewTestScriptSimplePasses()
    {
      // Use the Assert class to test conditions
      Assert.Inconclusive();
    }

    // A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
    // `yield return null;` to skip a frame.
    [UnityTest]
    public IEnumerator NewTestScriptWithEnumeratorPasses()
    {
      // Use the Assert class to test conditions.
      // Use yield to skip a frame.
      yield return null;
      Assert.Inconclusive();
    }
  }
}

The TestRunner does not provide me with any kind of feedback on the tests, except that they "didn't run" (number of green tests = number of failed tests = 0, number of not run tests = 2). I tried to restart Unity and run the tests again without any success.

That lack of feedback is interesting because if I set a breakpoint in both of those tests, then they're hit, i.e. the tests are run.

Same with 2018.4.3f1 and 2019.2.0b9.

Now if I reproduce that very experiment with Unity 2018.1.9f2, then

  • NewTestScriptSimplePasses provides no feedback at all
  • NewTestScriptWithEnumeratorPasses triggers an "InconclusiveException" in the console

If I replace the Assert.Inconclusive() with Assert.IsTrue(false), then I get proper feedback in the 2nd test. If I call Assert.IsTrue(true) in the 2nd test, then I get no feedback. In all cases (also those where I get an exception), the green / red ticks are not shown at all on the test runner.

What am I doing wrong? In EditorMode, everything is fine.

Thanks in advance for your help...

Aucun commentaire:

Enregistrer un commentaire