-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
The Deep Learning Protocol includes a comprehensive test suite with 7 XUnit tests covering all core functionality.
Test Framework: XUnit 2.9.2
Test Project: DeepLearningProtocol.Tests
Test File: DeepLearningProtocolTests.cs
# Run all tests
dotnet test
# Expected output:
# ✓ All tests pass (exit code 0)
# Test run time: ~1-2 seconds# Run single test by name
dotnet test --filter "GetCurrentState_ReturnsInitialState"
# Run tests matching pattern
dotnet test --filter "State"
# Run with verbose output
dotnet test --verbosity detailed# Generate code coverage report
dotnet test /p:CollectCoverage=true
# With detailed output
dotnet test --verbosity detailed /p:CollectCoverage=trueWhat it tests: State interface retrieval
Code:
[Fact]
public void GetCurrentState_ReturnsInitialState()
{
var protocol = new DeepLearningProtocol();
var state = protocol.GetCurrentState();
Assert.Equal("Initial", state);
}Purpose: Verify initial state is "Initial"
Category: State Management
Expected: PASS ✓
What it tests: State interface update
Code:
[Fact]
public void UpdateState_ChangesCurrentState()
{
var protocol = new DeepLearningProtocol();
protocol.UpdateState("New State");
var state = protocol.GetCurrentState();
Assert.Equal("New State", state);
}Purpose: Verify state can be updated
Category: State Management
Expected: PASS ✓
What it tests: Aim interface goal setting
Code:
[Fact]
public void SetAim_UpdatesAimAndState()
{
var protocol = new DeepLearningProtocol();
protocol.SetAim("Test Goal");
var state = protocol.GetCurrentState();
Assert.Contains("Test Goal", state);
}Purpose: Verify SetAim updates state with goal
Category: Aim Management
Expected: PASS ✓
What it tests: Aim interface pursuit
Code:
[Fact]
public void PursueAim_ReturnsCoreResultWithAim()
{
var protocol = new DeepLearningProtocol();
protocol.SetAim("Goal");
var result = protocol.PursueAim();
Assert.Contains("[Aim Pursuit]", result);
}Purpose: Verify PursueAim returns formatted result
Category: Aim Management
Expected: PASS ✓
What it tests: Depth processing with depth=0
Code:
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
public void ProcessAtDepth_AppliesCorrectDepth(int depth)
{
var protocol = new DeepLearningProtocol();
var result = protocol.ProcessAtDepth("input", depth);
// Verify number of [Abstract Core] layers equals depth
int layerCount = result.Split(new[] { "[Abstract Core]" }, StringSplitOptions.None).Length - 1;
Assert.Equal(depth, layerCount);
}Purpose: Verify depth processing creates correct number of layers
Depth Values Tested: 0, 1, 2
Category: Depth Processing
Expected: PASS ✓
What it tests: Complete protocol execution
Code:
[Fact]
public void ExecuteProtocol_FullFlow()
{
var protocol = new DeepLearningProtocol();
var result = protocol.ExecuteProtocol("Question", "Goal", 2);
Assert.Contains("[Aim Pursuit]", result);
Assert.Contains("[Abstract Core]", result);
Assert.Contains("Question", result);
}Purpose: Verify complete workflow executes correctly
Category: Integration
Expected: PASS ✓
Check DeepLearningProtocolTests.cs for complete list.
- ✓ GetCurrentState_ReturnsInitialState
- ✓ UpdateState_ChangesCurrentState
Purpose: Verify IStateInterface implementation
Coverage: State getter and setter
- ✓ SetAim_UpdatesAimAndState
- ✓ PursueAim_ReturnsCoreResultWithAim
Purpose: Verify IAimInterface implementation
Coverage: Goal setting and pursuing
- ✓ ProcessAtDepth_AppliesCorrectDepth (Theory with 0, 1, 2)
Purpose: Verify IDepthInterface recursive layering
Coverage: Depth levels 0-2
- ✓ ExecuteProtocol_FullFlow
Purpose: Verify complete workflow
Coverage: Full protocol execution with depth, aim, state
[Fact]
public void MethodName_Scenario_ExpectedBehavior()
{
// Arrange
var protocol = new DeepLearningProtocol();
var input = "test input";
// Act
var result = protocol.SomeMethod(input);
// Assert
Assert.NotNull(result);
Assert.Contains("expected", result);
}[Theory]
[InlineData("value1", "expected1")]
[InlineData("value2", "expected2")]
public void MethodName_Scenario_ExpectedBehavior(string input, string expected)
{
// Arrange
var protocol = new DeepLearningProtocol();
// Act
var result = protocol.SomeMethod(input);
// Assert
Assert.Contains(expected, result);
}- Open DeepLearningProtocolTests.cs
- Add method to
DeepLearningProtocolTestsclass - Use
[Fact]or[Theory]attribute - Follow AAA pattern (Arrange, Act, Assert)
- Run
dotnet testto verify
Example:
[Fact]
public void MyNewTest_Scenario_ExpectedResult()
{
// Arrange
var protocol = new DeepLearningProtocol();
// Act
var result = protocol.ExecuteProtocol("test", "goal", 1);
// Assert
Assert.NotNull(result);
Assert.Contains("[Aim Pursuit]", result);
}- ✅ Use descriptive test names:
Method_Scenario_Expected - ✅ Follow AAA pattern: Arrange, Act, Assert
- ✅ Use
[Theory]for multiple similar test cases - ✅ Test happy path AND edge cases
- ✅ Keep tests focused (one assertion per scenario)
- ✅ Use meaningful assertion messages
- ❌ Don't hardcode magic numbers (use variables)
- ❌ Don't mix multiple scenarios in one test
- ❌ Don't skip failed tests (fix them instead)
- ❌ Don't test internal implementation details
- ❌ Don't depend on test execution order
// Equality
Assert.Equal(expected, actual);
Assert.NotEqual(notExpected, actual);
// String operations
Assert.Contains("substring", "string");
Assert.StartsWith("prefix", "string");
Assert.EndsWith("suffix", "string");
// Null checks
Assert.Null(obj);
Assert.NotNull(obj);
// Boolean
Assert.True(condition);
Assert.False(condition);
// Exceptions
Assert.Throws<ExceptionType>(() => method());
var ex = Assert.Throws<ExceptionType>(() => method());
Assert.Equal("message", ex.Message);
// Collections
Assert.Single(collection);
Assert.Empty(collection);
Assert.Contains(item, collection);
Assert.DoesNotContain(item, collection);- Open DeepLearningProtocolTests.cs
- Set breakpoint by clicking line number
- Run test:
dotnet test --filter "TestName"(pauses at breakpoint) - Or use VS Code: F5 → select test file
dotnet test --verbosity detailedOutput shows each test step, useful for debugging failures.
Tests run automatically via GitHub Actions:
# In .github/workflows/dotnet.yml
- name: Run tests
run: dotnet testWhen tests run:
- On push to
main,master,develop - On pull request
- Manually via GitHub Actions
Success criteria:
- All tests pass (exit code 0)
- Coverage not below threshold (if configured)
All public methods of DeepLearningProtocol are covered:
- ✓ GetCurrentState() — Test 1
- ✓ UpdateState() — Test 2
- ✓ SetAim() — Test 3
- ✓ PursueAim() — Test 4
- ✓ ProcessAtDepth() — Test 5
- ✓ ExecuteProtocol() — Test 6
To improve coverage:
-
Test edge cases:
[Theory] [InlineData(0)] [InlineData(-1)] // Edge case: negative depth [InlineData(100)] // Edge case: very large depth public void ProcessAtDepth_EdgeCases(int depth) { }
-
Test error conditions:
[Fact] public void ExecuteProtocol_NullInput_HandlesGracefully() { var protocol = new DeepLearningProtocol(); // Should handle null or throw specific exception }
-
Test DLP integration:
[Fact] public void UpdateState_SuspiciousContent_Blocked() { var protocol = new DeepLearningProtocol(); protocol.UpdateState("meme_content.png"); Assert.Equal("[DLP-BLOCKED]", protocol.GetCurrentState()); }
Problem: dotnet test returns error
Solution:
dotnet clean
dotnet build
dotnet testProblem: CS compilation errors
Solution:
# Check syntax
dotnet build -v detailed
# Fix .csproj references if neededProblem: Test hangs indefinitely
Solution:
- Add timeout to test:
[Fact(Timeout = 5000)] - Check for infinite loops in code
- Use
asyncif test is I/O bound
Problem: Assert.Equal fails with "expected X, got Y"
Solution:
- Verify logic in code under test
- Add Debug.WriteLine() for logging
- Run with
--verbosity detailedfor more info
Tests run on:
- Trigger: Push to main/master/develop, Pull Requests
- Platform: ubuntu-latest
- Runtime: .NET 10.0
-
Steps:
- Checkout code
- Setup .NET
- Restore dependencies
- Build project
- Run tests
- (Optional) Collect coverage
Before pushing, always run:
# Full validation
dotnet clean && dotnet build && dotnet testIf all pass, safe to push.
# Time all tests
time dotnet test
# With detailed timing
dotnet test --logger "console;verbosity=detailed"-
Profile the code:
dotnet test --logger trx --collect:"XPlat Code Coverage"
-
Parallelize test execution:
dotnet test -p:ParallelizeAssembly=true -p:ParallelizeTestCollections=true -
Cache expensive operations:
private static readonly DeepLearningProtocol _cachedProtocol = new DeepLearningProtocol();
Next: Learn about DLP Protection to test protection mechanisms.
Previous: Read Architecture to understand what you're testing.