'How to unit test a console program that reads input and writes to the console [closed]
Let's say I have a simple program like
using System;
public class Solution
{
public static void Main(string[] args)
{
int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
Array.Sort(arr);
Console.WriteLine(string.Join(" ", arr));
}
}
which I want to test in a separate project like
[TestMethod]
public void TwoNumbersDescendingAreSwapped()
{
string input = "2 1";
string expectedOutput = "1 2";
// ... ???
Assert.AreEqual(expectedOutput, actualOutput);
}
Is it possible to do that without actually using the .exe from Solution?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
