Advanced testing utilities for Unity projects using MCP (Model Context Protocol). This package extends com.coplaydev.unity-mcp with additional testing capabilities including code coverage integration, advanced test filtering, and test result analysis.
-
Code Coverage Integration
- Enable/disable Unity Code Coverage recording
- Start and stop coverage recording programmatically
- Automatic HTML report generation
- Query coverage settings and status
-
Advanced Test Filtering (Coming Soon)
- Filter tests by pattern, category, or assembly
- Run specific test subsets via MCP commands
-
Test Result Analysis (Coming Soon)
- Parse Unity TestResults.xml files
- Extract test statistics and failure information
- Analyze test execution data programmatically
-
CI/CD Integration
- Designed for automated testing workflows
- Compatible with GitHub Actions, Jenkins, GitLab CI
- Supports batch mode execution
- Unity 2022.3 or later
- com.coplaydev.unity-mcp version 6.0.0 or later
- Unity Test Framework 1.4.0 or later
- Optional: com.unity.testtools.codecoverage for code coverage features
- Open Unity Package Manager (
Window → Package Manager) - Click the
+button in the top-left corner - Select
Add package from git URL... - Enter:
https://github.com/The1Studio/UnityTestUtilitiesMCP.git - Click
Add
Add the following to your Packages/manifest.json:
{
"dependencies": {
"com.the1studio.unity-test-utilities-mcp": "https://github.com/The1Studio/UnityTestUtilitiesMCP.git",
"com.coplaydev.unity-mcp": "6.0.0",
"com.unity.test-framework": "1.4.0"
}
}# Clone into your Unity project's Packages directory
cd Packages/
git submodule add https://github.com/The1Studio/UnityTestUtilitiesMCP.git
# Update submodules
git submodule update --init --recursiveFor code coverage features, install the Unity Code Coverage package:
# Via Package Manager
Window → Package Manager → Unity Registry → Code Coverage → Install
# Or add to manifest.json
"com.unity.testtools.codecoverage": "1.2.0"- Ensure Unity MCP is configured in your Unity Editor (
Window → MCP for Unity) - Click
Auto-Setupif not already connected - Verify "Connected" status appears
# Enable code coverage with auto-report generation
mcp__UnityTestUtilitiesMCP__enable_code_coverage '{"enabled": true, "autoGenerateReport": true}'
# Start recording coverage
mcp__UnityTestUtilitiesMCP__start_coverage_recording '{}'
# Run your tests in Unity Editor (Window → General → Test Runner)
# Stop recording and generate report
mcp__UnityTestUtilitiesMCP__stop_coverage_recording '{"generateReport": true}'
# Query coverage settings
mcp__UnityTestUtilitiesMCP__get_coverage_settings '{}'When using Claude Code CLI with Unity MCP:
User: "Enable code coverage and run tests"
Claude:
1. Calls enable_code_coverage tool with enabled=true
2. Calls start_coverage_recording tool
3. Prompts user to run tests in Unity Test Runner
4. Calls stop_coverage_recording with generateReport=true
5. Reports coverage results path
Enables or disables Unity Code Coverage recording.
Parameters:
enabled(boolean, required): True to enable coverage, false to disableautoGenerateReport(boolean, optional): If true, automatically generate HTML report after recording stops. Default: false
Returns:
{
"enabled": true,
"autoGenerateReport": true,
"coverageResultsPath": "/path/to/project/CodeCoverage"
}Example:
{"enabled": true, "autoGenerateReport": true}Starts recording code coverage data. Coverage must be enabled first.
Parameters: None
Returns:
{
"recording": true,
"coverageResultsPath": "/path/to/project/CodeCoverage"
}Example:
{}Stops recording code coverage data and optionally generates an HTML report.
Parameters:
generateReport(boolean, optional): If true, generate HTML report after stopping. Default: false
Returns:
{
"recording": false,
"reportGenerated": true,
"reportPath": "/path/to/project/CodeCoverage/Report/index.html",
"coverageResultsPath": "/path/to/project/CodeCoverage"
}Example:
{"generateReport": true}Queries current code coverage settings and status.
Parameters: None
Returns:
{
"coveragePackageInstalled": true,
"enabled": true,
"autoGenerateReport": true,
"coverageResultsPath": "/path/to/project/CodeCoverage",
"recording": true
}Example:
{}# Step 1: Check coverage availability
mcp__UnityTestUtilitiesMCP__get_coverage_settings '{}'
# Step 2: Enable coverage
mcp__UnityTestUtilitiesMCP__enable_code_coverage '{"enabled": true}'
# Step 3: Start recording
mcp__UnityTestUtilitiesMCP__start_coverage_recording '{}'
# Step 4: Run tests manually in Unity Test Runner
# Window → General → Test Runner → Run All
# Step 5: Stop recording and generate report
mcp__UnityTestUtilitiesMCP__stop_coverage_recording '{"generateReport": true}'
# Step 6: Open report in browser
# File located at: <project>/CodeCoverage/Report/index.html# Enable coverage with auto-report generation
mcp__UnityTestUtilitiesMCP__enable_code_coverage '{"enabled": true, "autoGenerateReport": true}'
# Start recording
mcp__UnityTestUtilitiesMCP__start_coverage_recording '{}'
# Run tests...
# Stop recording (report automatically generated)
mcp__UnityTestUtilitiesMCP__stop_coverage_recording '{}'# Query current settings
mcp__UnityTestUtilitiesMCP__get_coverage_settings '{}'
# Example response:
{
"coveragePackageInstalled": true,
"enabled": true,
"autoGenerateReport": false,
"coverageResultsPath": "/home/user/MyProject/CodeCoverage",
"recording": false
}name: Unity Tests with Coverage
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Unity
uses: game-ci/unity-builder@v2
with:
unityVersion: 2022.3.0f1
- name: Run Tests with Coverage
run: |
# Enable code coverage
unity-editor -batchmode -quit -projectPath . \
-executeMethod UnityTestUtilitiesMCP.EnableCoverage
# Run tests
unity-editor -batchmode -quit -projectPath . \
-runTests -testPlatform EditMode
# Generate coverage report
unity-editor -batchmode -quit -projectPath . \
-executeMethod UnityTestUtilitiesMCP.GenerateCoverageReport
- name: Upload Coverage Report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: CodeCoverage/Report/pipeline {
agent any
stages {
stage('Setup') {
steps {
checkout scm
}
}
stage('Enable Coverage') {
steps {
sh '''
/opt/Unity/Editor/Unity -batchmode -quit \
-projectPath . \
-executeMethod UnityTestUtilitiesMCP.EnableCoverage
'''
}
}
stage('Run Tests') {
steps {
sh '''
/opt/Unity/Editor/Unity -batchmode -quit \
-projectPath . \
-runTests -testPlatform EditMode
'''
}
}
stage('Generate Coverage Report') {
steps {
sh '''
/opt/Unity/Editor/Unity -batchmode -quit \
-projectPath . \
-executeMethod UnityTestUtilitiesMCP.GenerateCoverageReport
'''
}
}
stage('Publish Coverage') {
steps {
publishHTML([
reportDir: 'CodeCoverage/Report',
reportFiles: 'index.html',
reportName: 'Code Coverage Report'
])
}
}
}
}Error: "Code Coverage package (com.unity.testtools.codecoverage) is not installed."
Solution: Install the Code Coverage package via Package Manager:
- Open
Window → Package Manager - Select
Unity Registryfrom the dropdown - Search for "Code Coverage"
- Click
Install
Issue: Coverage recording doesn't capture any data.
Solutions:
- Ensure coverage is enabled:
mcp__UnityTestUtilitiesMCP__get_coverage_settings '{}' - Verify recording started before running tests
- Check Unity Console for error messages
- Restart Unity Editor and try again
Issue: HTML report is not generated.
Solutions:
- Check that coverage data exists in
CodeCoverage/directory - Ensure tests were run after starting recording
- Verify Unity has write permissions to project directory
- Check Unity Console for detailed error messages
Issue: MCP tools not available or not responding.
Solutions:
- Verify Unity MCP is installed and configured (
Window → MCP for Unity) - Click
Auto-Setupin MCP for Unity window - Restart Unity Editor
- Check that
com.coplaydev.unity-mcpversion 6.0.0+ is installed
Important: Never run Unity in batch mode while Unity Editor is open when using Unity MCP. This will cause connection conflicts and may corrupt project state.
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone the repository
git clone https://github.com/The1Studio/UnityTestUtilitiesMCP.git
# Create a Unity project for testing
mkdir TestProject
cd TestProject
unity-hub create --name TestProject --version 2022.3.0f1
# Link package for local development
cd Packages
ln -s /path/to/UnityTestUtilitiesMCP com.the1studio.unity-test-utilities-mcp- Follow Unity C# coding conventions
- Use PascalCase for classes, methods, and properties
- Use camelCase for private fields
- Add XML documentation comments for public APIs
- Include error handling and logging
- Add unit tests for new features in
Tests/directory - Ensure all tests pass before submitting PR
- Test with Unity MCP integration
MIT License
Copyright (c) 2024 The1Studio
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For issues, questions, or feature requests:
- Open an issue on GitHub
- Contact The1Studio team
- ✅ Code coverage enable/disable
- ✅ Coverage recording start/stop
- ✅ HTML report generation
- ✅ Coverage settings query
- Advanced test filtering by pattern
- Test filtering by category
- Test filtering by assembly
- Run filtered tests via MCP
- Parse TestResults.xml files
- Extract test statistics
- Analyze test failures
- Test result query API
- Batch test operations
- Custom report templates
- Coverage threshold validation
- Test execution history tracking