TEXT_TESTS_ANALYSIS.md 9.3 KB

Text Tests Deep Dive and Migration Analysis

Overview

The Text/ folder in UnitTests contains 27 tests across 2 files that focus on text formatting and autocomplete functionality. This analysis examines each test to determine migration feasibility.

Test Files Summary

File Total Tests AutoInitShutdown SetupFakeDriver No Attributes Migratable
TextFormatterTests.cs 23 0 18 5 15-18 (refactor)
AutocompleteTests.cs 4 2 0 2 2 (migrated)
TOTAL 27 2 18 7 17-20 (63-74%)

AutocompleteTests.cs - Detailed Analysis

✅ MIGRATED (2 tests)

1. Test_GenerateSuggestions_Simple

Status: ✅ Migrated to UnitTests.Parallelizable

  • Type: Pure unit test
  • Tests: Suggestion generation logic
  • Dependencies: None (no Application, no Driver)
  • Why migratable: Tests internal logic only

2. TestSettingSchemeOnAutocomplete

Status: ✅ Migrated to UnitTests.Parallelizable

  • Type: Pure unit test
  • Tests: Scheme/color configuration
  • Dependencies: None (no Application, no Driver)
  • Why migratable: Tests property setting only

❌ REMAIN IN UNITTESTS (2 tests)

3. CursorLeft_CursorRight_Mouse_Button_Pressed_Does_Not_Show_Popup

Status: ❌ Must remain in UnitTests

  • Type: Integration test
  • Tests: Popup display behavior with keyboard/mouse interaction
  • Dependencies: [AutoInitShutdown], Application.Begin(), DriverAssert
  • Why not migratable:
    • Tests full UI interaction workflow
    • Verifies visual rendering of popup
    • Requires Application.Begin() to set up event loop
    • Uses DriverAssert to verify screen content

4. KeyBindings_Command

Status: ❌ Must remain in UnitTests

  • Type: Integration test
  • Tests: Keyboard navigation in autocomplete popup
  • Dependencies: [AutoInitShutdown], Application.Begin()
  • Why not migratable:
    • Tests keyboard command handling in context
    • Requires Application event loop
    • Verifies state changes across multiple interactions

TextFormatterTests.cs - Detailed Analysis

Test Categorization

All 23 tests use [SetupFakeDriver] and test TextFormatter's Draw() method. However, many are testing formatting logic rather than actual rendering.

🟡 REFACTORABLE TESTS (15-18 tests can be converted)

These tests can be converted from testing Draw() output to testing Format() logic:

Horizontal Alignment Tests (10 tests) - HIGH PRIORITY

  1. Draw_Horizontal_Centered (Theory with 9 InlineData)

    • Tests horizontal centering logic
    • Conversion: Use Format() instead of Draw(), verify string output
  2. Draw_Horizontal_Justified (Theory with 9 InlineData)

    • Tests text justification (Fill alignment)
    • Conversion: Use Format() instead of Draw()
  3. Draw_Horizontal_Left (Theory with 8 InlineData)

    • Tests left alignment
    • Conversion: Use Format() instead of Draw()
  4. Draw_Horizontal_Right (Theory with 8 InlineData)

    • Tests right alignment
    • Conversion: Use Format() instead of Draw()

Direction Tests (2 tests)

  1. Draw_Horizontal_RightLeft_TopBottom (Theory with 11 InlineData)

    • Tests right-to-left text direction
    • Conversion: Use Format() to test string manipulation logic
  2. Draw_Horizontal_RightLeft_BottomTop (Theory with 9 InlineData)

    • Tests right-to-left, bottom-to-top direction
    • Conversion: Use Format() to test string manipulation

Size Calculation Tests (2 tests) - EASY WINS

  1. FormatAndGetSize_Returns_Correct_Size

    • Tests size calculation without actually rendering
    • Conversion: Already doesn't need Draw(), just remove SetupFakeDriver
  2. FormatAndGetSize_WordWrap_False_Returns_Correct_Size

    • Tests size calculation with word wrap disabled
    • Conversion: Already doesn't need Draw(), just remove SetupFakeDriver

Tab Handling Tests (3 tests) - EASY WINS

  1. TabWith_PreserveTrailingSpaces_False

    • Tests tab expansion logic
    • Conversion: Use Format() to verify tab handling
  2. TabWith_PreserveTrailingSpaces_True

    • Tests tab expansion with preserved spaces
    • Conversion: Use Format() to verify tab handling
  3. TabWith_WordWrap_True

    • Tests tab handling with word wrap
    • Conversion: Use Format() to verify logic

❌ KEEP IN UNITTESTS (5-8 tests require actual rendering)

These tests verify actual console driver behavior and should remain:

Vertical Layout Tests (Variable - need individual assessment)

  1. Draw_Vertical_BottomTop_LeftRight

    • Complex vertical text layout
    • May need driver to verify correct glyph positioning
  2. Draw_Vertical_BottomTop_RightLeft

    • Complex vertical text with RTL
    • May need driver behavior
  3. Draw_Vertical_Bottom_Horizontal_Right

    • Mixed orientation layout
    • Driver-dependent positioning
  4. Draw_Vertical_TopBottom_LeftRight

  5. Draw_Vertical_TopBottom_LeftRight_Middle

  6. Draw_Vertical_TopBottom_LeftRight_Top

    • Various vertical alignments
    • Some may be convertible, others may need driver

Unicode/Rendering Tests (MUST STAY)

  1. Draw_With_Combining_Runes

    • Tests Unicode combining character rendering
    • Must stay: Verifies actual glyph composition in driver
  2. Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds

    • Tests error handling with invalid bounds
    • Must stay: Tests Draw() method directly

Complex Tests (NEED INDIVIDUAL REVIEW)

  1. Draw_Text_Justification (Theory with 44 InlineData)

    • Massive test with many scenarios
    • Some may be convertible, others may need driver
  2. Justify_Horizontal

    • Tests justification logic
    • Possibly convertible
  3. UICatalog_AboutBox_Text

    • Tests real-world complex text
    • May need driver for full verification

Conversion Strategy

Step 1: Easy Conversions (5 tests - 30 minutes)

Convert tests that already mostly test logic:

  • FormatAndGetSize_Returns_Correct_Size
  • FormatAndGetSize_WordWrap_False_Returns_Correct_Size
  • TabWith_PreserveTrailingSpaces_False
  • TabWith_PreserveTrailingSpaces_True
  • TabWith_WordWrap_True

Change required:

// Before
[SetupFakeDriver]
[Theory]
[InlineData(...)]
public void Test_Name(params)
{
    tf.Draw(...);
    DriverAssert.AssertDriverContentsWithFrameAre(expected, _output);
}

// After  
[Theory]
[InlineData(...)]
public void Test_Name(params)
{
    var result = tf.Format();
    Assert.Equal(expected, result);
}

Step 2: Alignment Test Conversions (10 tests - 1-2 hours)

Convert horizontal alignment tests (Centered, Justified, Left, Right):

  • Replace Draw() with Format()
  • Remove DriverAssert, use Assert.Equal on string
  • Test output logic without driver

Step 3: Direction Test Conversions (2 tests - 30 minutes)

Convert RightLeft direction tests:

  • These manipulate strings, not render-specific
  • Use Format() to verify string reversal logic

Step 4: Evaluate Vertical Tests (Variable - 1-2 hours)

Individually assess each vertical test:

  • Some may be convertible to Format() logic tests
  • Others genuinely test driver glyph positioning
  • Keep those that need driver behavior

Step 5: Complex Test Assessment (3 tests - 1-2 hours)

Evaluate Draw_Text_Justification, Justify_Horizontal, UICatalog_AboutBox_Text:

  • May require splitting into logic + rendering tests
  • Logic parts can migrate, rendering parts stay

Expected Results

After Full Migration

  • Migrated to Parallelizable: 17-20 tests (63-74%)
  • Remaining in UnitTests: 7-10 tests (26-37%)
    • 2 Autocomplete integration tests
    • 5-8 TextFormatter rendering tests

Performance Impact

  • Current Text/ tests: ~10.18s for 467 tests (from performance analysis)
  • After migration: Estimated 8-9s for remaining integration tests
  • Savings: ~1.2-2.2s (12-22% reduction in Text/ folder)

Test Quality Improvements

  1. Better test focus: Separates logic testing from rendering testing
  2. Faster feedback: Logic tests run in parallel without driver overhead
  3. Clearer intent: Tests named Format* clearly test logic, Draw* test rendering
  4. Easier maintenance: Logic tests don't depend on driver implementation details

Conclusion

The Text/ folder is an excellent candidate for migration because:

  1. 2 tests already migrated with zero refactoring (AutocompleteTests)
  2. 15-18 tests are testing logic but using driver unnecessarily
  3. Clear conversion pattern exists (Draw → Format)
  4. High success rate: 63-74% of tests can be migrated

The remaining 26-37% are legitimate integration tests that verify actual rendering behavior and should appropriately remain in UnitTests.

Next Steps

  1. DONE: Migrate 2 AutocompleteTests (Test_GenerateSuggestions_Simple, TestSettingSchemeOnAutocomplete)
  2. TODO: Convert 5 easy TextFormatterTests (FormatAndGetSize, TabWith tests)
  3. TODO: Convert 10 alignment tests (Horizontal Centered/Justified/Left/Right)
  4. TODO: Assess and convert 2-5 additional tests
  5. TODO: Document remaining tests as integration tests

Report Created: 2025-10-20 Tests Analyzed: 27 tests across 2 files Migration Status: 2/27 migrated (7.4%), 15-18/27 planned (63-74% total potential)