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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Can create a single test for a specific device?

Discussion in 'Testing & Automation' started by MHR_171, Dec 19, 2022.

  1. MHR_171

    MHR_171

    Joined:
    Apr 1, 2015
    Posts:
    7
    Overview:

    I am working with Unity 2021.3.4f1
    I use Unity Test Framework 1.1.33 for testing

    The previous developer designed a bunch of test cases just for Windows Editor
    However, the new test case requires an Android environment to run

    The test cases look as follows
    upload_2022-12-19_16-43-27.png

    Goal:

    What I want is, whenever I run UnitTest --> Android section it will do the same as "Run All Tests (adnroid)" button, which is:
    1. build .apk file
    2. run the .apk on the (currently an emulator) Android environment
    3. Get the test result

    What I've done so far:

    Thanks to this forum
    I tried to run the Split Build and Run scenario. But every time I run the example code, this kind of error always appears
    Assets\Scripts\Tests\Testing.cs(2,19): error CS0234: The type or namespace name 'TestTools' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)


    And then I bump into this forum that said that I have to check the "Enable playmode tests for all assemblies" option.

    And sadly that is also fails so I bump into this forum but I have no luck on finding the "Enable playmode tests for all assemblies" option
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    What Assembly Definition Files do you have and where, and how have you set up the platforms in them?
     
  3. MHR_171

    MHR_171

    Joined:
    Apr 1, 2015
    Posts:
    7
    Thanks for replying
    This is the screen capture of my Assembly definition fileds
    upload_2022-12-20_7-43-46.png

    I want to add "Unity Test-Framework" as Assembly reference there (next to "nunit.framework.dll")
    However, it doesn't exist

    So, in the next part, I added this thing
    upload_2022-12-20_7-45-35.png

    > how have you set up the platforms in them?

    That's the thing that I want to ask
    Is it correct if I follow the Split Build and Run scenario?
    Because so far I just tried to use "Run all test (android)" button, to test whether its working or not
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    There is no such assembly as 'Unity Test-Framework', so that makes sense. The references that you already have look OK, but if you want your tests to be able to run outside of the Editor then I think you should remove the reference to UnityEditor.TestRunner.

    You don't need that.

    It should be, yes. Can you share what your Assets\Scripts\Tests\Testing.cs file looks like?
     
  5. MHR_171

    MHR_171

    Joined:
    Apr 1, 2015
    Posts:
    7
    Sadly that doesn't work

    upload_2022-12-20_20-35-4.png

    This is the content of Assets\Scripts\Testing\Testing.cs

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.TestTools;
    3.  
    4. [assembly:TestPlayerBuildModifier(typeof(BuildModifier))]
    5. public class BuildModifier : ITestPlayerBuildModifier
    6. {
    7.     public BuildPlayerOptions ModifyOptions(BuildPlayerOptions playerOptions)
    8.     {
    9.         if (playerOptions.target == BuildTarget.iOS)
    10.         {
    11.             playerOptions.options |= BuildOptions.SymlinkLibraries; // Enable symlink libraries when running on iOS
    12.         }
    13.  
    14.         playerOptions.options |= BuildOptions.AllowDebugging; // Enable allow Debugging flag on the test Player.
    15.         return playerOptions;
    16.     }
    17. }
     
    Last edited: Dec 20, 2022
  6. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    Ahh, you need to have your ITestPlayerBuilModifier be in a separate folder with a separate assembly definition file which is marked for the Editor platform only, I think.
     
  7. MHR_171

    MHR_171

    Joined:
    Apr 1, 2015
    Posts:
    7
    Sadly this doesn't worked

    upload_2022-12-21_7-56-0.png
    The error keep following the script
    upload_2022-12-21_7-56-34.png
    Even I put it in the root folder, but it seems like Unity Engine is not happy with it
     
  8. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    You need to add the UnityEditor.TestTools assembly reference to your new assembly definition file
     
  9. MHR_171

    MHR_171

    Joined:
    Apr 1, 2015
    Posts:
    7
    Oh, I see. I'll try this solution once I'm done dealing with my current problem
    Thanks for your reply