unity-mcp/TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/RunTestsTests.cs

67 lines
2.1 KiB
C#
Raw Normal View History

Feature/run tests summary clean (#501) * Optimize run_tests to return summary by default, reducing token usage by 98% - Add includeFailedTests parameter: returns only failed/skipped test details - Add includeDetails parameter: returns all test details (original behavior) - Default behavior now returns summary only (~150 tokens vs ~13k tokens) - Make results field optional in Python schema for backward compatibility Token savings: - Default: ~13k tokens saved (98.9% reduction) - With failures: minimal tokens (only non-passing tests) - Full details: same as before when explicitly requested This prevents context bloat for typical test runs where you only need pass/fail counts, while still allowing detailed debugging when needed. * Add warning when run_tests filters match no tests; fix test organization TDD Feature: - Add warning message when filter criteria match zero tests - New RunTestsTests.cs validates message formatting logic - Modified RunTests.cs to append "(No tests matched the specified filters)" when total=0 Test Organization Fixes: - Move MCPToolParameterTests.cs from EditMode/ to EditMode/Tools/ (matches folder hierarchy) - Fix inconsistent namespaces to MCPForUnityTests.Editor.{Subfolder}: - MCPToolParameterTests: Tests.EditMode → MCPForUnityTests.Editor.Tools - DomainReloadResilienceTests: Tests.EditMode.Tools → MCPForUnityTests.Editor.Tools - Matrix4x4ConverterTests: MCPForUnityTests.EditMode.Helpers → MCPForUnityTests.Editor.Helpers * Refactor test result message formatting * Simplify RunTests warning assertions * Tests: de-flake cold-start EditMode runs - Make ManageScriptableObjectTests setup yield-based with longer Unity-ready timeout - Mark DomainReloadResilienceTests explicit to avoid triggering domain reload during Run All
2026-01-02 12:36:45 +08:00
using System;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using MCPForUnity.Editor.Services;
namespace MCPForUnityTests.Editor.Tools
{
/// <summary>
/// Tests for RunTests tool functionality.
/// Note: We cannot easily test the full HandleCommand because it would create
/// recursive test runner calls. Instead, we test the message formatting logic.
/// </summary>
public class RunTestsTests
{
[Test]
public void FormatResultMessage_WithNoTests_IncludesWarning()
{
// Arrange
var summary = new TestRunSummary(
total: 0,
passed: 0,
failed: 0,
skipped: 0,
durationSeconds: 0.0,
resultState: "Passed"
);
var result = new TestRunResult(summary, new TestRunTestResult[0]);
// Act
string message = MCPForUnity.Editor.Tools.RunTests.FormatTestResultMessage("EditMode", result);
// Assert - THIS IS THE NEW FEATURE
Assert.IsTrue(
message.Contains("No tests matched"),
$"Expected warning when total=0, but got: '{message}'"
);
}
[Test]
public void FormatResultMessage_WithTests_NoWarning()
{
// Arrange
var summary = new TestRunSummary(
total: 5,
passed: 4,
failed: 1,
skipped: 0,
durationSeconds: 1.5,
resultState: "Failed"
);
var result = new TestRunResult(summary, new TestRunTestResult[0]);
// Act
string message = MCPForUnity.Editor.Tools.RunTests.FormatTestResultMessage("EditMode", result);
// Assert
Assert.IsFalse(
message.Contains("No tests matched"),
$"Should not have warning when tests exist, but got: '{message}'"
);
Assert.IsTrue(message.Contains("4/5 passed"), "Should contain pass ratio");
}
// Use MCPForUnity.Editor.Tools.RunTests.FormatTestResultMessage directly.
}
}