Replies: 1 comment 3 replies
-
What I do is have a method that creates the parser data structures and takes in For example, something like: [Theory]
[InlineData("quiet", LogLevel.Quiet)]
[InlineData("detailed", LogLevel.Detailed)]
public async Task ValidateFooBarVerbosity(string input, LogLevel expected)
{
CliCommand parser = FooBarCommand.Create(ValidateArguments);
_ = await parser.Parse($"foo -v {input}").InvokeAsync();
async Task ValidateArguments(FooBarArguments args)
{
args.Verbosity.Should().Be(expected);
}
} Writing tests for error conditions is a bit different, instead of This way I can write many exhaustive tests for the CLI parsing, without it actually executing the product code, so it's nice and fast to execute and doesn't have side effects. |
Beta Was this translation helpful? Give feedback.
-
Looking for advice and example code on how to add unit tests for CLI parsing correctness?
Some way to provide a string, run parse on it, then test for success/failure and value presence, seems not too difficult, but is there a way to express the results in e.g. xUnit
[Theory]
section?Beta Was this translation helpful? Give feedback.
All reactions