M
M
Melz2016-11-11 17:46:28
.NET
Melz, 2016-11-11 17:46:28

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

but would like an alternative. Including for running tests in parallel.
Sawing 100500 interfaces? The internet is full of contradictions...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-11-11
@melz

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" ConsoleWrapperand 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 question

Ask a Question

731 491 924 answers to any question