Skip to main content
ClaudeWave
Slash Command65 estrellas del repoactualizado yesterday

test-dotnet

Run .NET/C# tests for Unity projects and backend services

Instalar en Claude Code
Copiar
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/solanabr/solana-ai-kit/HEAD/.claude/commands/test-dotnet.md -o ~/.claude/commands/test-dotnet.md
Después abre una sesión nueva de Claude Code; el slash command carga automáticamente.

test-dotnet.md

You are running .NET/C# tests. This command covers Unity Test Framework (Edit Mode and Play Mode) and standard .NET testing.

## Related Skills

- [unity.md](../skills/unity.md) - Unity patterns and testing
- [playsolana.md](../skills/playsolana.md) - PlaySolana specifics

---

## TDD Workflow (6 Phases)

When developing with TDD, follow these phases strictly:

### Phase 1: RED - Write Failing Test

1. Create test file in appropriate location (`Tests/EditMode/` or `Tests/PlayMode/`)
2. Write minimal test that fails for the right reason
3. Run test to confirm it fails
4. **Do NOT write production code yet**

```csharp
[Test]
public void Calculate_WithValidInput_ReturnsExpected()
{
    var sut = new Calculator();  // Class doesn't exist yet

    var actual = sut.Calculate(10, 2);

    Assert.That(actual, Is.EqualTo(12));
}
```

### Phase 2: GREEN - Make Test Pass

1. Write minimal production code to pass the test
2. **Only write enough code to pass** - no more
3. Run test to confirm it passes
4. Commit if green

```csharp
public class Calculator
{
    public int Calculate(int a, int b) => a + b;  // Minimal implementation
}
```

### Phase 3: REFACTOR - Clean Up

1. Improve code structure without changing behavior
2. Run tests after each refactoring step
3. Keep tests green throughout
4. Apply SOLID principles, remove duplication

### Phase 4: Iterate

1. Return to Phase 1 for next test case
2. Build up functionality incrementally
3. Each cycle: RED → GREEN → REFACTOR

### Phase 5: Integration

1. After unit tests pass, run integration tests
2. Test component interactions
3. For Unity: run Play Mode tests

### Phase 6: Review

1. Review test coverage
2. Check for missing edge cases
3. Ensure tests are maintainable
4. Remove any redundant tests

---

## Core Workflow: Build → Respond → Iterate

Operate in fast, surgical development cycles with minimal token usage.

### Execution Flow

1. **Understand the Request**: Analyze minimum code required
2. **Make the Change**: Implement surgical edit
3. **Build**: `dotnet build --no-restore --nologo --verbosity minimal`
4. **If Build Fails**: Retry once if obvious fix, then **STOP and ask**
5. **Run Tests**: `dotnet test --no-build --nologo --verbosity minimal`
6. **If Tests Fail**: Extract failures with `rg`, fix if obvious, else **STOP and ask**

### Two-Strike Rule

If build or test fails twice on the same issue:
1. **STOP** immediately
2. Present the error output
3. Show the code change made
4. Ask for user guidance

---

## Step 1: Identify Project Type

```bash
echo "🔍 Detecting .NET project type..."

if [ -f "ProjectSettings/ProjectVersion.txt" ]; then
    echo "🎮 Unity project detected"
    PROJECT_TYPE="unity"
    cat ProjectSettings/ProjectVersion.txt
elif [ -f "*.sln" ] || [ -f "*.csproj" ]; then
    echo "📦 .NET solution/project detected"
    PROJECT_TYPE="dotnet"
else
    echo "❓ No .NET project found"
    exit 1
fi
```

---

## Unity Test Framework

### Run All Tests

```bash
echo "🧪 Running Unity tests..."

# Run all tests (Edit Mode + Play Mode)
unity-editor -runTests -batchmode -nographics \
    -projectPath . \
    -testResults TestResults.xml \
    -logFile test.log

# Check results
if [ $? -eq 0 ]; then
    echo "✅ All tests passed!"
else
    echo "❌ Some tests failed"
    # Parse results
    grep -E "Failed|Error" test.log | head -20
fi
```

### Run Edit Mode Tests Only

```bash
echo "📝 Running Edit Mode tests..."

unity-editor -runTests -batchmode -nographics \
    -projectPath . \
    -testPlatform EditMode \
    -testResults EditModeResults.xml \
    -logFile editmode.log

if [ $? -eq 0 ]; then
    echo "✅ Edit Mode tests passed!"
else
    echo "❌ Edit Mode tests failed"
    grep -E "Failed|Error" editmode.log | head -20
fi
```

### Run Play Mode Tests Only

```bash
echo "🎮 Running Play Mode tests..."

unity-editor -runTests -batchmode -nographics \
    -projectPath . \
    -testPlatform PlayMode \
    -testResults PlayModeResults.xml \
    -logFile playmode.log

if [ $? -eq 0 ]; then
    echo "✅ Play Mode tests passed!"
else
    echo "❌ Play Mode tests failed"
    grep -E "Failed|Error" playmode.log | head -20
fi
```

### Run Specific Test Assembly

```bash
# Run tests from specific assembly
unity-editor -runTests -batchmode -nographics \
    -projectPath . \
    -testPlatform EditMode \
    -assemblyNames "MyGame.Tests" \
    -testResults Results.xml \
    -logFile test.log
```

### Run Specific Test Class or Method

```bash
# Run specific test class
unity-editor -runTests -batchmode -nographics \
    -projectPath . \
    -testFilter "WalletServiceTest" \
    -testResults Results.xml \
    -logFile test.log

# Run specific test method
unity-editor -runTests -batchmode -nographics \
    -projectPath . \
    -testFilter "WalletServiceTest.Connect_WithValidCredentials_ReturnsTrue" \
    -testResults Results.xml \
    -logFile test.log
```

### Parse Test Results

```bash
echo "📊 Parsing test results..."

if [ -f "TestResults.xml" ]; then
    # Count results
    TOTAL=$(grep -c "test-case" TestResults.xml || echo "0")
    PASSED=$(grep -c 'result="Passed"' TestResults.xml || echo "0")
    FAILED=$(grep -c 'result="Failed"' TestResults.xml || echo "0")

    echo "Total: $TOTAL | Passed: $PASSED | Failed: $FAILED"

    # Show failed tests
    if [ "$FAILED" -gt 0 ]; then
        echo ""
        echo "❌ Failed tests:"
        grep -B1 'result="Failed"' TestResults.xml | grep "name=" | head -10
    fi
fi
```

---

## Standard .NET Testing

### Run All Tests

```bash
echo "🧪 Running .NET tests..."

# Restore and build first
dotnet restore
dotnet build --no-restore --configuration Release

# Run tests
dotnet test --no-build --configuration Release \
    --logger "console;verbosity=normal" \
    --results-directory TestResults

if [ $? -eq 0 ]; then
    echo "✅ All tests passed!"
else
    echo "❌ Some tests failed"
fi
```

### Run Tests with Coverage

```bash
echo "📊 Running tests with coverage..."

dotnet test --no-build --c
anchor-engineerSubagent

Anchor framework specialist for rapid Solana program development. Use for building programs with Anchor macros, IDL generation, account validation, and standardized patterns. Prioritizes developer experience while maintaining security.\\n\\nUse when: Building new programs quickly, team projects needing standardization, projects requiring IDL for client generation, or when developer experience is prioritized over maximum CU optimization.

defi-engineerSubagent

DeFi integration specialist for composing with Solana protocols including Jupiter, Drift, Kamino, Raydium, Orca, Meteora, Marginfi, and Sanctum. Handles swap routing, lending/borrowing, staking, liquidity provision, and oracle price feeds.\n\nUse when: Integrating DeFi protocols, building swap interfaces, implementing lending/borrowing, setting up yield strategies, working with Pyth/Switchboard oracles, or composing multi-protocol transactions.

devops-engineerSubagent

CI/CD, infrastructure, and deployment specialist for Solana projects. Handles GitHub Actions, Docker, monitoring, RPC management, and Cloudflare Workers edge deployment.\n\nUse when: Setting up CI/CD pipelines, containerizing Solana validators or programs, configuring monitoring and alerting, managing RPC infrastructure, deploying edge workers, or automating build and deploy workflows.

game-architectSubagent

Senior Solana game architect for game system design, Unity/C# architecture, on-chain game state, player progression, NFT integration, and PlaySolana ecosystem. Use for high-level game design decisions, architecture reviews, and planning complex game systems.\n\nUse when: Designing new Solana games from scratch, planning game state on-chain, Unity project architecture, integrating with PlaySolana/PSG1, or deciding between implementation approaches.

mobile-engineerSubagent

React Native and Expo specialist for building Solana mobile dApps. Handles mobile wallet adapter integration, transaction signing UX, deep linking, and mobile-specific performance optimization.\n\nUse when: Building React Native or Expo mobile apps with Solana integration, implementing mobile wallet adapter flows, setting up deep links for transaction signing, or optimizing mobile dApp performance.

pinocchio-engineerSubagent

CU optimization specialist using Pinocchio framework. Use for performance-critical programs requiring 80-95% CU reduction vs Anchor. Specializes in zero-copy access, manual validation, and minimal binary size.\\n\\nUse when: CU limits are being hit, transaction costs are significant at scale, binary size must be minimized, or maximum throughput is required.

rust-backend-engineerSubagent

Rust backend specialist for building async services that interact with Solana blockchain. Builds APIs, indexing services, and off-chain processing using Axum, Tokio, and modern async patterns.\n\nUse when: Building REST/WebSocket APIs for Solana dApps, implementing transaction indexers, creating webhook services, or any Rust backend that interacts with Solana.

solana-architectSubagent

Senior Solana program architect for system design, account structures, PDA schemes, token economics, and cross-program composability. Use for high-level design decisions, architecture reviews, and planning complex multi-program systems.\n\nUse when: Designing new programs from scratch, planning account structures, optimizing PDA schemes, reviewing architecture for security, or deciding between implementation approaches.