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
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
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));
}