Search Unity

Excluding playmode tests from build

Discussion in 'Testing & Automation' started by bartofzo, Jun 3, 2022.

  1. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    151
    Hi,

    I want to run play mode tests, but only inside of the editor. But when I only check Editor on the asmdef file, the play mode tests aren't found with the message: "Playmode test scripts can only be created in non editor test assemblies"

    How do I go about this? I don't want the play mode test code to be included in a build.

    Thanks
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    Are you certain they are included when you create a playmode test folder using the asset menu? I doubt they are being built into a player. Playmode tests always run in the editor but a „internal“ test build is created before running them.
     
  3. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    151
    Hm, I assumed the scripts inside the folder will be included in the build, because the build targets are checked on the asmdef file. Am I wrong about this?
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    Assemblies which reference nunit.framework.dll will only be included in the build if BuildOptions.IncludeTestAssemblies is passed as an option, regardless of what platforms you have set on the asmdef.
     
  5. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    151
    Good to know! Thanks.
     
  6. jamie_xr

    jamie_xr

    Joined:
    Feb 28, 2020
    Posts:
    67
    I'm having issues with this @superpig
    My test assembly is created as follows
    upload_2022-12-12_10-25-21.png

    This currently won't build. I get the following error:
    Code (CSharp):
    1. ArgumentException: The Assembly UnityEngine.TestRunner is referenced by XXX ('Library/PlayerScriptAssemblies/XXX.dll'). But the dll is not allowed to be included or could not be found.
    2. UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1[T] alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2[TKey,TValue] cache, UnityEditor.BuildTarget target) (at <36f62d8e760b48f7af5d32916f997ce1>:0)
    3. UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[] paths, System.String[] foldersToSearch, UnityEditor.BuildTarget target) (at <36f62d8e760b48f7af5d32916f997ce1>:0)
    4. UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()
    5.  
    If I make the assembly definition include Editor only, the build works but my tests disappear from the PlayMode tab of the test runner.
     
  7. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    Try adding UNITY_INCLUDE_TESTS to your asmdef as a Define Constraint.
     
  8. jamie_xr

    jamie_xr

    Joined:
    Feb 28, 2020
    Posts:
    67
    That worked. Thanks