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

Unable to create custom attribute for UnityTest because IEnumerableTestMethodCommand is internal

Discussion in 'Testing & Automation' started by skazmierczak, Dec 6, 2021.

  1. skazmierczak

    skazmierczak

    Joined:
    Feb 28, 2020
    Posts:
    9
    I want to create a custom attribute for my Unity play mode tests ([UnityTest]). I am unable to do so, because
    IEnumerableTestMethodCommand is internal, and when i dont implement it, i get the following error:

    ```'MyCustomAttribute' is not supported on UnityTestAttribute as it does not handle returning IEnumerator.```
     
  2. skazmierczak

    skazmierczak

    Joined:
    Feb 28, 2020
    Posts:
    9
    Any ideas?
     
  3. sbergen

    sbergen

    Joined:
    Jan 12, 2015
    Posts:
    53
    I found a workaround, but it includes using inheritance in the test class and also decorating the test class with an attribute. You might be able to get rid of the class attribute though, it just wasn't needed for my use case.
    (If I haven't yet implemented tests for that, I'm sorry about all the coverage warnings in the diff :D )

    Essentially, you implement a method in the base class, which takes IMethodInfo to invoke the wrapped method and returns IEnumerator. And when building the test suite, you point NUnit to running that method with the required arguments.

    Still, it would be nice if there was some more direct way of doing this.