Skip to content

Fix run_tests response #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Editor/Tools/RunTestsTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public void TestStarted(ITestAdaptor test)
// Called when a test finishes
public void TestFinished(ITestResultAdaptor result)
{
// Skip test suites (tests with children)
if (result.Test.HasChildren)
{
return;
}

_testResults.Add(new TestResult
{
Name = result.Test.Name,
Expand All @@ -136,8 +142,11 @@ public void RunFinished(ITestResultAdaptor result)
// Create test results summary
var summary = new JObject
{
["testCount"] = _testResults.Count,
["passCount"] = _testResults.FindAll(r => r.Passed).Count,
["testCount"] = result.PassCount + result.FailCount + result.SkipCount + result.InconclusiveCount,
["passCount"] = result.PassCount,
["failCount"] = result.FailCount,
["skipCount"] = result.SkipCount,
["inconclusiveCount"] = result.InconclusiveCount,
["duration"] = result.Duration,
["success"] = result.ResultState == "Passed",
["status"] = "completed",
Expand Down Expand Up @@ -166,7 +175,13 @@ public void RunFinished(ITestResultAdaptor result)
{
["success"] = true,
["type"] = "text",
["message"] = summary["message"].Value<string>()
["message"] = summary["message"].Value<string>(),
["testCount"] = summary["testCount"],
["passCount"] = summary["passCount"],
["failCount"] = summary["failCount"],
["skipCount"] = summary["skipCount"],
["inconclusiveCount"] = summary["inconclusiveCount"],
["results"] = summary["results"]
});
}
catch (Exception ex)
Expand Down
9 changes: 7 additions & 2 deletions Server/build/tools/runTestsTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ async function toolHandler(mcpUnity, params) {
const testResults = response.results || [];
const testCount = response.testCount || 0;
const passCount = response.passCount || 0;
const failCount = response.failCount || 0;
const inconclusiveCount = response.inconclusiveCount || 0;
const skipCount = response.skipCount || 0;
// Format the result message
let resultMessage = `${passCount}/${testCount} tests passed`;
if (testCount > 0 && passCount < testCount) {
Expand All @@ -69,14 +72,16 @@ async function toolHandler(mcpUnity, params) {
content: [
{
type: 'text',
text: response.message || resultMessage
text: resultMessage || response.message
},
{
type: 'text',
text: JSON.stringify({
testCount,
passCount,
failCount: testCount - passCount,
failCount,
inconclusiveCount,
skipCount,
results: testResults
}, null, 2)
}
Expand Down
9 changes: 7 additions & 2 deletions Server/src/tools/runTestsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ async function toolHandler(mcpUnity: McpUnity, params: any): Promise<CallToolRes
const testResults = response.results || [];
const testCount = response.testCount || 0;
const passCount = response.passCount || 0;
const failCount = response.failCount || 0;
const inconclusiveCount = response.inconclusiveCount || 0;
const skipCount = response.skipCount || 0;

// Format the result message
let resultMessage = `${passCount}/${testCount} tests passed`;
Expand All @@ -89,14 +92,16 @@ async function toolHandler(mcpUnity: McpUnity, params: any): Promise<CallToolRes
content: [
{
type: 'text',
text: response.message || resultMessage
text: resultMessage || response.message
},
{
type: 'text',
text: JSON.stringify({
testCount,
passCount,
failCount: testCount - passCount,
failCount,
inconclusiveCount,
skipCount,
results: testResults
}, null, 2)
}
Expand Down