Skip to content

Commit

Permalink
feature: add parameters to cli tool (#31)
Browse files Browse the repository at this point in the history
* feature: add parameters to cli tool

* fix: fix issue with globbing working folder

* docs: add basic readme text on package description

* ci: add script for local verification, update script docs

* docs: add per project readme, trim package docs to basic text

* ci: bump minor version
  • Loading branch information
kurtmkurtm authored Sep 18, 2022
1 parent 6efa9ef commit 8cde737
Show file tree
Hide file tree
Showing 26 changed files with 450 additions and 94 deletions.
70 changes: 16 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](assets/fish_logo.png)
![Fish logo](assets/fish_logo.png)

Liquid Test Reports are logger extensions for the [Visual Studio Test Platform](https://gtihub.com/microsoft/vstest) that provide flexible test report generation using liquid templates. This project contains an extensible core for code based extension, a custom logger for providing your own templates without code, and a Markdown implementation.

Expand All @@ -15,27 +15,21 @@ Liquid Test Reports are logger extensions for the [Visual Studio Test Platform](

### Latest:

##### 1.3.2 beta
- [Cli]
- Add parameter support for the CLI based on the logger implementation
- Fix issue where folder wasn't being used at file load time

#### 1.3.2 beta

- [Cli]
- Add filename pattern matching support for CLI

##### 1.2.1 beta
#### 1.2.1 beta

- [Cli]
- Add JUnit XML support
- Change template input to use file instead of content string

##### 1.1.1 beta

- [Cli]
- Add new .NET Tool for report generation with TRX support
- Add new markdown report template
- [Core]
- Refactor drop model mapping
- Add TRX mapping
- Move template error logging from report generator into base test logger

[Previous changes](./docs/Changelog.md)


Expand Down Expand Up @@ -64,16 +58,19 @@ liquid [options]
- **Format=report-format;** Optional input report format, case insensitive, supported values are `Trx` of `JUnit`. Defaults to `Trx`.
- **GroupTitle=group-title;** Optional title to group reports under, test runs with the same group title will be merged.
- **TestPrefix=test-prefix;** Optional test suffix, if provided test origination for the provided report will have the suffix appended to its name.
- **key=value;** Optional key value pairs, only for custom template usage.

**--parameters [parameters]** Array of formatted key value strings for custom template usage, with configurations separated by a semicolon

**--output-file [output-file]** Path to save test report to.

**--title [title]** Optional overall report title displayed in default report template. Defaults to "Test Run"
**--title [title]** Optional overall report title displayed in default report template. Defaults to "Test Run".

**--template [template]** Optional user defined liquid template. Defaults to the multi report markdown template is used.

**--version** Show version information
**--version** Show version information.

**-?, -h, --help** Show help and usage information
**-?, -h, --help** Show help and usage information.

#### Examples

Expand All @@ -83,51 +80,16 @@ liquid [options]
liquid --inputs "File=xUnit-net461-junit-sample.xml;Format=JUnit" --output-file report.md
```

**TRX to Markdown**- [Sample Output](docs/samples/cli/SingleInput.md)
**TRX to Markdown** - [Sample Output](docs/samples/cli/SingleInput.md)

```bash
liquid --inputs "File=xUnit-net461-sample.trx;Format=Trx" --output-file SingleInput.md
```

#### More Examples

**File glob pattern relative to current directory**

```bash
liquid --inputs "File=**/*sample.trx" --output-file report.md
```
**File glob pattern using specific directory**
```bash
liquid --inputs "File=**/*sample.trx;Folder=C:\MyTestFolder" --output-file report.md
```

**Report from single input, with a custom title** - [Sample Output](docs/samples/cli/CustomTitle.md)

``` bash
liquid --inputs "File=xUnit-net461-sample.trx" --output-file CustomTitle.md --title "Test Run 2021"
```

**Report from two inputs** - [Sample Output](docs/samples/cli/TwoInputs.md)

``` bash
liquid --inputs "File=xUnit-net461-sample.trx" "File=xUnit-netcoreapp3.1-sample.trx" --output-file TwoInputs.md
```
**Multiple Report inputs, grouping, and custom template usage**

**Grouped results** - [Sample Output](docs/samples/cli/GroupUnitTests.md)
Report with two inputs, and results grouped under the same section "Unit Tests":
- [More Examples](./docs/CliExamples.md)

``` bash
liquid --inputs "File=xUnit-net461-sample.trx;GroupTitle=Unit Tests" "File=xUnit-netcoreapp3.1-sample.trx;GroupTitle=Unit Tests" --output-file GroupUnitTests.md
```

**Grouped results with test name suffix** - [Sample Output](docs/samples/cli/GroupAndSuffix.md)

Report from two inputs, grouped under the same section "Unit Tests", with the tests from `xUnit-netcoreapp3.1-sample.trx` having (3.1) appended to the test names
eg `SampleProject.xUnit.TestServiceTests` becomes `SampleProject.xUnit.TestServiceTests.PassingTest(3.1)`

``` bash
liquid --inputs "File=xUnit-net461-sample.trx;GroupTitle=Unit Tests" "File=xUnit-netcoreapp3.1-sample.trx;GroupTitle=Unit Tests;TestSuffix=(3.1)" --output-file GroupAndSuffix.md
```

#### Removal

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pool:
variables:
buildConfiguration: 'Release'
majorVersion: 1
minorVersion: 3
minorVersion: 4
suffix: 'beta'

stages:
Expand Down
10 changes: 10 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## Changelog

#### 1.1.1 beta

- [Cli]
- Add new .NET Tool for report generation with TRX support
- Add new markdown report template
- [Core]
- Refactor drop model mapping
- Add TRX mapping
- Move template error logging from report generator into base test logger

#### 1.0.9

**Changed**
Expand Down
48 changes: 48 additions & 0 deletions docs/CliExamples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Additional Cli Samples



**File glob pattern relative to current directory**

```bash
liquid --inputs "File=**/*sample.trx" --output-file report.md
```

**File glob pattern using specific directory**
```bash
liquid --inputs "File=**/*sample.trx;Folder=C:\MyTestFolder" --output-file report.md
```

**Report from single input, with a custom title** - [Sample Output](./samples/cli/CustomTitle.md)

``` bash
liquid --inputs "File=xUnit-net461-sample.trx" --output-file CustomTitle.md --title "Test Run 2021"
```

**Report from two inputs** - [Sample Output](./samples/cli/TwoInputs.md)

``` bash
liquid --inputs "File=xUnit-net461-sample.trx" "File=xUnit-netcoreapp3.1-sample.trx" --output-file TwoInputs.md
```

**Grouped results** - [Sample Output](./samples/cli/GroupUnitTests.md)
Report with two inputs, and results grouped under the same section "Unit Tests":

``` bash
liquid --inputs "File=xUnit-net461-sample.trx;GroupTitle=Unit Tests" "File=xUnit-netcoreapp3.1-sample.trx;GroupTitle=Unit Tests" --output-file GroupUnitTests.md
```

**Grouped results with test name suffix** - [Sample Output](./samples/cli/GroupAndSuffix.md)

Report from two inputs, grouped under the same section "Unit Tests", with the tests from `xUnit-netcoreapp3.1-sample.trx` having (3.1) appended to the test names
eg `SampleProject.xUnit.TestServiceTests` becomes `SampleProject.xUnit.TestServiceTests.PassingTest(3.1)`

``` bash
liquid --inputs "File=xUnit-net461-sample.trx;GroupTitle=Unit Tests" "File=xUnit-netcoreapp3.1-sample.trx;GroupTitle=Unit Tests;TestSuffix=(3.1)" --output-file GroupAndSuffix.md
```

**Custom template and parameter**- [Sample Input](./samples/cli/InputTemplate.md) [Sample_Output](./samples/cli/CustomParameters.md)

```bash
liquid --inputs "File=**/*sample.trx;Format=Trx;RunId=123" --template="InputTemplate.md" --parameters="Environment=UAT;TicketId=abc123" --output-file CustomParameters.md
```
43 changes: 43 additions & 0 deletions docs/samples/cli/CustomParameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Test Run
### Run Summary


- Test Environment: UAT
- Ticket Reference: abc123
- Overall Result: ❌ Fail
- Pass Rate: 33.33%
- Total Tests: 36


---


#### SampleProject.MSTest.dll

Run Id: 123
Pass Rate: 33.33%
Tests: 12

---


#### SampleProject.NUnit.dll

Run Id: 123
Pass Rate: 33.33%
Tests: 12

---


#### SampleProject.xUnit.dll

Run Id: 123
Pass Rate: 33.33%
Tests: 12

---



[Created using Liquid Test Reports](https://github.com/kurtmkurtm/LiquidTestReports)
43 changes: 43 additions & 0 deletions docs/samples/cli/InputTemplate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{%- assign passed = run.test_run_statistics.passed_count -%}
{%- assign failed = run.test_run_statistics.failed_count -%}
{%- assign skipped = run.test_run_statistics.skipped_count -%}
{%- assign total = run.test_run_statistics.executed_tests_count -%}
{%- assign pass_percentage = passed | divided_by: total | times: 100.0 | round: 2 *-%}
{%- if passed == total -%}
{%- assign overall = '✔️ Pass' *-%}
{%- elsif failed == 0 -%}
{%- assign overall = '⚠️ Indeterminate' *-%}
{%- else -%}
{%- assign overall = '❌ Fail' *-%}
{%- endif -%}
# {{ library.parameters.Title }}
### Run Summary


- Test Environment: {{ parameters.Environment }}
- Ticket Reference: {{ parameters.TicketId }}
- Overall Result: {{overall}}
- Pass Rate: {{pass_percentage}}%
- Total Tests: {{total}}


---

{%- for set in run.result_sets -%} {%- assign groups = set.results | group: 'outcome' *-%}
{%- assign group_total = set.results | size *-%}
{%- assign passed_total = groups.Passed | size *-%}
{%- assign failed_total = groups.Failed | size *-%}
{%- assign skipped_total = groups.Skipped | size *-%}

#### {{ set.source }}

Run Id: {{ set.parameters.RunId }}
Pass Rate: {{ passed_total | divide_by_decimal: group_total | times: 100.0 | round: 2 }}%
Tests: {{ set.results | size }}

---

{%- endfor -%}


[{{ library.text }}]({{ library.link }})
12 changes: 11 additions & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Scripts

### createtrxfiles

Runs sample project unit tests with NUnit, xUnit, and MSTest to regenerate trx files for use in CLI integration tests

### createjuitfiles

Runs sample project unit tests with NUnit, xUnit, and MSTest to regenerate junit files for use in CLI integration tests

### updateproperties

Runs sample project unit tests with xUnit to populate sample output for documentation

### regenerateschema

Regenerates models from xml schema for JUnit and VSTS
Regenerates models from xml schema for JUnit and VSTS

### clilocaltest

Uninstalls local packages and installs specified cli build then runs test, requires manual modification for package version
12 changes: 12 additions & 0 deletions scripts/clilocaltest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
dotnet tool uninstall LiquidTestReports.Cli -g # remove old version
dotnet tool install --global --add-source ./ LiquidTestReports.Cli --version latest # must be specified for beta eg 1.3.5-beta

liquid `
--inputs "File=**/*sample.trx;Folder=../Test/LiquidTestReports.Cli.Tests/TrxTestInput" `
--output-file report.md

liquid `
--inputs "File=**/*sample.trx;Folder=../Test/LiquidTestReports.Cli.Tests/TrxTestInput;Format=Trx;RunId=123" `
--template "../Test/LiquidTestReports.Cli.Tests/TemplateTestInput/example.md" `
--parameters "Environment=UAT;TicketId=abc123" `
--output-file custom.md
6 changes: 4 additions & 2 deletions src/LiquidTestReports.Cli/ConsoleRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ internal class ConsoleRunner
private readonly IAnsiConsole _standardConsole;
private readonly ReportInput[] _inputs;
private readonly FileInfo _outputFile;
private readonly ParametersInput _parameters;

internal ConsoleRunner(ReportInput[] inputs, FileInfo outputFile)
internal ConsoleRunner(ReportInput[] inputs, FileInfo outputFile, ParametersInput parameters)
{
_errorConsole = AnsiConsole.Create(new AnsiConsoleSettings { Out = new AnsiConsoleOutput(Console.Error) });
_standardConsole = AnsiConsole.Create(new AnsiConsoleSettings { Out = new AnsiConsoleOutput(Console.Out) });
_inputs = inputs;
_outputFile = outputFile;
_parameters = parameters;
}

internal void Run(string title, string template)
Expand Down Expand Up @@ -101,7 +103,7 @@ private string GenerateReport(string template, LibraryDrop libraryDrop)

try
{
var reportGenerator = new ReportGenerator(new LibraryTestRun { Run = run, Library = libraryDrop });
var reportGenerator = new ReportGenerator(new LibraryTestRun { Run = run, Library = libraryDrop, Parameters = _parameters?.Parameters });
report = reportGenerator.GenerateReport(template ?? Templates.MdMultiReport, out var errors);
foreach (var error in errors)
_standardConsole.MarkupLine($"[orange1]{error.Message}[/]");
Expand Down
8 changes: 6 additions & 2 deletions src/LiquidTestReports.Cli/LiquidTestReports.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<ToolCommandName>liquid</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<RepositoryUrl>https://github.com/kurtmkurtm/LiquidTestReports</RepositoryUrl>
<PackageProjectUrl>https://github.com/kurtmkurtm/LiquidTestReports</PackageProjectUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>nuget_cli.png</PackageIcon>
<PackageIcon>nuget_cli.png</PackageIcon>
<Description>
LiquidTestReports.Cli Generates Markdown and Custom Test Reports from TRX and or JUnit test files.
The output will look like this https://github.com/kurtmkurtm/LiquidTestReports/blob/master/docs/samples/cli/SingleInput.md
</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="5.0.0" />
Expand Down
Loading

0 comments on commit 8cde737

Please sign in to comment.