Excluding playmode tests from build

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

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.

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?

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.

Good to know! Thanks.

I’m having issues with this @superpig
My test assembly is created as follows

This currently won’t build. I get the following error:

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.
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)
UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[] paths, System.String[] foldersToSearch, UnityEditor.BuildTarget target) (at <36f62d8e760b48f7af5d32916f997ce1>:0)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()

If I make the assembly definition include Editor only, the build works but my tests disappear from the PlayMode tab of the test runner.

Try adding UNITY_INCLUDE_TESTS to your asmdef as a Define Constraint.

That worked. Thanks