Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Can I use Assert.ThrowsAsync?

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

  1. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    325
    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
     
    ChrisVMC likes this.