Search Issue Tracker

Won't Fix

Votes

11

Found in

2018.2.3f1

Issue ID

1071259

Regression

No

Test Runner UI shows that Async / Await tests were successful when these tests have failed

Unity Test Runner

-

The Assertion failure gets logged into the Unity console when the Test fails but the Test Runner UI shows a green tick and doesn't wait for NUnit's eventual assertion failure.

To reproduce:

1. Download attached project "Unity2018-asyncawait-tests.zip" and open in Unity
2. Open "SampleScene" scene
3. Open Test Runner window
4. In Test Runner window press "PlayMode" button
5. Press the "Run All" button
6. Observe that Assertion failure appears in the Console window when a Test fails but there is no Tests fail in the Test Runner window

Notes:
- This issue appears on both Windows and OSX

Reproduced on Unity 2017.1.5f1, 2017.2.3p3, 2017.3.2f1, 2017.4.9f1, 2018.1.9f1, 2018.2.3f1 and 2018.3.0a9

  1. Resolution Note (2019.1.X):

    async await is not supported in the in the nunit version we are running. We might revisit this if we upgrade the nunit version in the future.

    A workaround for it could be to use UnityTest and then yield null until the task is completed.
    Example:
    [UnityTest]
    public IEnumerator AsyncAwaitTest1()
    {
    var tester = new AsyncAwaitTester();

    var task = tester.SlowAdder(22, 20);
    while (!task.IsCompleted)
    {
    yield return null;
    }

    Assert.That(task.Result, Is.EqualTo(420));
    }

Comments (3)

  1. ModLunar

    Mar 30, 2021 17:42

    Wow.. this is kind of upsetting.
    Won't fix at all?
    Ever?

    Will the Test Framework (Unity package) ever be updated with a newer version of NUnit that supports async tests?
    It's pretty important for me to test async code in my Unity projects.
    I guess I could do more in pure C# Visual Studio solutions.. but.. :/

  2. cyberflixtvapp

    Jan 21, 2020 15:18

    Cyberflix tv is the best android app for watching movies and tv shows online on https://cyberflixtvapp.info/cyberflix-tv-apk/ Android smartphones, Firestick as well as on Windows PC. You will also be able to download Cybeflix TV on Android TV boxes.

  3. kyptov

    Dec 14, 2018 11:38

    I hate coroutine, but here the working solution to bypass
    ```
    [UnityTest]
    public IEnumerator TestAsync()
    {
    // replace public async void with public IEnumerator
    // change all await to getting Task

    // Result result = await LoadAsync();
    Task<Result> task = LoadAsync();

    // infinity loop
    while (!task.IsCompleted)
    {
    yield return null;
    }

    Result result = task.Result;

    // do assertion here
    }
    ```

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.