@@ -45,10 +45,12 @@ class RunTestsResponse(MCPResponse):
4545)
4646async def run_tests (
4747 ctx : Context ,
48- mode : Annotated [Literal ["EditMode" , "PlayMode" ], Field (
49- description = "Unity test mode to run" )] = "EditMode" ,
50- timeout_seconds : Annotated [int | str , Field (
51- description = "Optional timeout in seconds for the Unity test run (string, e.g. '30')" )] | None = None ,
48+ mode : Annotated [Literal ["EditMode" , "PlayMode" ], "Unity test mode to run" ] = "EditMode" ,
49+ timeout_seconds : Annotated [int | str , "Optional timeout in seconds for the test run" ] | None = None ,
50+ test_names : Annotated [list [str ] | str , "Full names of specific tests to run (e.g., 'MyNamespace.MyTests.TestMethod')" ] | None = None ,
51+ group_names : Annotated [list [str ] | str , "Same as test_names, except it allows for Regex" ] | None = None ,
52+ category_names : Annotated [list [str ] | str , "NUnit category names to filter by (tests marked with [Category] attribute)" ] | None = None ,
53+ assembly_names : Annotated [list [str ] | str , "Assembly names to filter tests by" ] | None = None ,
5254) -> RunTestsResponse :
5355 unity_instance = get_unity_instance_from_context (ctx )
5456
@@ -68,11 +70,39 @@ def _coerce_int(value, default=None):
6870 except Exception :
6971 return default
7072
73+ # Coerce string or list to list of strings
74+ def _coerce_string_list (value ) -> list [str ] | None :
75+ if value is None :
76+ return None
77+ if isinstance (value , str ):
78+ return [value ] if value .strip () else None
79+ if isinstance (value , list ):
80+ result = [str (v ).strip () for v in value if v and str (v ).strip ()]
81+ return result if result else None
82+ return None
83+
7184 params : dict [str , Any ] = {"mode" : mode }
7285 ts = _coerce_int (timeout_seconds )
7386 if ts is not None :
7487 params ["timeoutSeconds" ] = ts
7588
89+ # Add filter parameters if provided
90+ test_names_list = _coerce_string_list (test_names )
91+ if test_names_list :
92+ params ["testNames" ] = test_names_list
93+
94+ group_names_list = _coerce_string_list (group_names )
95+ if group_names_list :
96+ params ["groupNames" ] = group_names_list
97+
98+ category_names_list = _coerce_string_list (category_names )
99+ if category_names_list :
100+ params ["categoryNames" ] = category_names_list
101+
102+ assembly_names_list = _coerce_string_list (assembly_names )
103+ if assembly_names_list :
104+ params ["assemblyNames" ] = assembly_names_list
105+
76106 response = await send_with_unity_instance (async_send_command_with_retry , unity_instance , "run_tests" , params )
77107 await ctx .info (f'Response { response } ' )
78108 return RunTestsResponse (** response ) if isinstance (response , dict ) else response
0 commit comments