Skip to content

Testability: ProcessHelper and ProcessKiller are static — cannot be mocked #430

@Christophe-Rogiers

Description

@Christophe-Rogiers

Description

Two critical helper classes are entirely static with no interfaces:

ProcessHelper (src/Servy.Core/Helpers/ProcessHelper.cs)

  • GetCpuUsage(int pid), GetRamUsage(int pid), ResolvePath(), ValidatePath(), FormatCpuUsage(), FormatRamUsage()
  • Called from MainViewModel.RefreshServiceInternal (lines 900–901) and PerformanceViewModel.OnTickAsync (lines 310–313)
  • Tests must deal with real Process.GetProcessById calls

ProcessKiller (src/Servy.Core/Helpers/ProcessKiller.cs)

  • KillProcessesUsingFile(), KillProcessTreeAndParents()
  • Called from MainWindow cleanup and ResourceHelper
  • Tests cannot verify process-killing behavior

Impact

Any test of refresh, performance, or cleanup logic requires real process handles. Cannot verify behavior with specific PIDs, failure scenarios, or access-denied conditions.

Suggested fix

Wrap behind interfaces (IProcessHelper, IProcessKiller) and inject. The existing code uses instance-based DI for most other services — these two are the main holdouts.

Metadata

Metadata

Assignees

Labels

testsChanges to test code and coverage

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions