Instrumenting AnsiConsole
for testing
#1535
Closed
yenneferofvengerberg
started this conversation in
Ideas
Replies: 1 comment 6 replies
-
@yenneferofvengerberg Out of curiousity, have you taken a look at the Spectre.Console.Testing library and the TestConsole? |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
All of our tools heavily use
spectre.console
, however depending on the purpose of the test and which interactivity we need, there are several mocks (at different levels). To avoid serializing the tests on theSystem.Console
object we relegated all the console-based operations into methods that are protected by an ugly (but effective)if (IsUnitTesting)...
.This works like a charm, but leaves out more that 50% of the code from the unit test, and usually the defects are there.
In order to at least perform a smoke test on the remaining part, AnsiConsole
should be turned into a moral equivalent of
ITestOutputHelper`. I couldn't find a viable solution (or alternative) to achieve that in the source code. To achieve my goal I could introduce several other mocks and further reorganize the code, but I would like to solve the problem in a transparent way if possible.Assuming that the tests are asynchronous, by altering
AnsiConsole
as followsAnsiConsole
can now be fed with an instrumenter like this:The rationale is that the test would be responsible for initializing the context via
Initialize
, the rest would be unchanged.Is this a viable solution? Is this something you are interested in integrate if I create a PR for it?
Beta Was this translation helpful? Give feedback.
All reactions