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
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
Comments (3)
-
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.. :/ -
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
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Editor hangs when painting Details containing 2D Mesh on Terrain
- No audio is played when TimelinePlayable has one output
- Scene and Sprite Editor views break when an edge is deleted in an attempt to split geometry
- Specular lighting visible in a camera with Path Tracing when Preserve specular lighting is disabled in observed material
- Cinemachine package throws CS1061 errors in the Console when installed in a project that has HDRP and URP installed
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));
}