Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Can I use Assert.ThrowsAsync?

Discussion in 'Testing & Automation' started by Maeslezo, Oct 3, 2022.

  1. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    255
    Hello,

    I am trying to use Assert.ThrowsAsync, but I am getting an infinite loop when I play the test that it's using it.

    Can I use it? Does it suppose to work? Otherwise, I can report a bug

    Code (CSharp):
    1.         [Test]
    2.         public async Task Tests()
    3.         {
    4.            
    5.             Assert.ThrowsAsync<ArgumentException>(async () => await MethodThatThrows());
    6.         }
    7.  
    8.         async Task MethodThatThrows()
    9.         {
    10.             await Task.Delay(100);
    11.             throw new ArgumentException();
    12.         }
    upload_2022-10-3_15-57-53.png

    Unity 2020.3.30f
    Test Framework 2.0.1-pre.18

    Thank you