Answer the question
In order to leave comments, you need to log in
How are Console being tested these days?
Hello!
It's simple:
- console program
- text input / output from the console. (no color, etc.)
Need to test I/O pairs with NUnit.
At the moment everything is WORKING through
Console.SetOut and StringWriter
Answer the question
In order to leave comments, you need to log in
This is exactly the problem for the solution of which they came up with Dependency Injection. If you hardwire to a static class Console
, you have to put up with its limitations, in particular, single-threading.
The most competent solution, for which you will not be ashamed, is indeed to use DI and an interface. We will have to implement two classes based on it - "combat" ConsoleWrapper
and test ConsoleWrapperMock
.
As a quick and dirty solution - if the program is simple and you can test everything through the input parameters, you can run it as an external process in the test (call the exe file) - then the processes will be independent of each other and the tests can be run in parallel.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question