'Testing Process.Start?
I am creating an application that manages multiple instances of an external utility, supplying each with data and fetching results.
But I'm facing a problem writing unit tests.
How to test if the target method actually starts a process (set via a property) when called?
I have tried:
- Make the class execute an external process and then use
GetProcessesByName()to check if it has started. - Use output redirection, e.g. using the greater-than sign to echo something to a file and test its existence
I feel like creating yet another .exe to test it is overkill.
Code:
public void Start()
{
if (!_isRunning)
{
var startInfo = new ProcessStartInfo() {
CreateNoWindow = true,
UseShellExecute = true,
FileName = _cmdLine,
Arguments = _args
};
_process = Process.Start(startInfo);
_isRunning = true;
}
else
{
throw new InvalidOperationException("Process already started");
}
}
I want to unit-test it so that a new process should start if nothing is running (_isRunning == false).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
