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 Bugs with Parameterized Test Fixtures

Discussion in 'Testing & Automation' started by YVR_Unity, Feb 19, 2022.

  1. YVR_Unity

    YVR_Unity

    Joined:
    Jun 17, 2021
    Posts:
    3
    I have made a parameterized test fixture in play mode which exactly the same with the demo code in nunit official documentation:TestFixture | NUnit Docs, as the attached file "ParameterizedTestFixture.cs".

    but he Unit Test Runner window shows error for this testfixture:

    ParameterizedTestFixture (0.000s)
    ---
    An exception was thrown while loading the test.
    System.ArgumentNullException: pathName
    Parameter name: Argument pathName must not be null



    If i add a namespace for the testfixture, sth like:
    Code (CSharp):
    1. namespace Test
    2. {
    3.     [TestFixture]
    4.     [TestFixture("hello", "hello", "goodbye")]
    5.     [TestFixture("zip", "zip")]
    6.     [TestFixture(42, 42, 99)]
    7.     public class ParameterizedTestFixture
    8.     {
    9.      // .....
    10.     }
    11. }
    Then all tests work well in unity editor (still in play mode), but when i run tests in android platform, the following error occurred for every test:

    No suitable constructor was found


    How should i use parameterized test fixture in android platform?
     

    Attached Files:

  2. sbergen

    sbergen

    Joined:
    Jan 12, 2015
    Posts:
    42
    This looks like it could be a code stripping issue, which happens because the constructor will be called through reflection. You could try adding
    [Preserve]
    to the constructors to see if that would help.
     
  3. YVR_Unity

    YVR_Unity

    Joined:
    Jun 17, 2021
    Posts:
    3
    Wow, Really thanks.

    After adding [UnityEngine.Scripting.Preserve] attribute to all constructors, all tests passed in android platform.

    But i am still curious about why i have to add namespace for parameterized test fixture?