Skip to content

Commit 5f8aa56

Browse files
committed
Expand and clarify README test instructions
Significantly reorganize and expand README.md with detailed guidance for running tests locally and in Linux Docker. Add sections on standard vs. Explicit test runs, trait-based filtering, parallelism control, and best practices for test output and CI parity. Reformat Linux Docker instructions for clarity and improve overall usability.
1 parent fbfea1e commit 5f8aa56

1 file changed

Lines changed: 71 additions & 7 deletions

File tree

Source/Tst/README.md

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,79 @@
1-
# Tips for running linux unit tests.
1+
# Tests folder
2+
3+
This document covers **local `dotnet test`** workflows (standard vs Explicit) and **Linux Docker** runs.
4+
5+
Unless noted otherwise, run commands from the **`Source`** directory (the folder that contains `KZDev.PerfUtils.sln`). The solution uses **artifacts output** (`UseArtifactsOutput`); test build outputs live under **`artifacts/bin/<ProjectName>/release_net*`** at the repository root, not under each project’s `bin` folder.
6+
7+
---
8+
9+
## Local: standard full suite (Release)
10+
11+
Restores, builds, and runs **non-Explicit** tests with the defaults wired in `Directory.Build.props` / `Directory.Build.targets` (`xunit.runner.json`, `KZDev.PerfUtils.tests.runsettings`).
12+
13+
**PowerShell or cmd (from `Source`):**
14+
15+
```cmd
16+
dotnet restore KZDev.PerfUtils.sln
17+
dotnet build KZDev.PerfUtils.sln -c Release
18+
dotnet test KZDev.PerfUtils.sln -c Release --no-build
19+
```
20+
21+
**bash (from `Source`):**
22+
23+
```bash
24+
dotnet restore KZDev.PerfUtils.sln
25+
dotnet build KZDev.PerfUtils.sln -c Release
26+
dotnet test KZDev.PerfUtils.sln -c Release --no-build
27+
```
28+
29+
`[Fact(Explicit = true)]` tests are **skipped** in this default configuration.
30+
31+
---
32+
33+
## Local: Explicit-only run (serialized xUnit)
34+
35+
Explicit stress tests are marked with **`[Trait(TestMode, Explicit)]`** (see `KZDev.PerfUtils.TestBase/TestConstants.cs`: trait name **`TestMode`**, value **`Explicit`**). Prefer **trait-based** selection so shared test sources are not tied to fragile method-name lists.
36+
37+
This repository’s `dotnet test` path uses **VSTest** (not Microsoft Testing Platform by default). Use a VSTest **`--filter`** for the trait, and pass **xUnit RunSettings** after `--` so explicit tests **execute** and xUnit runs **single-threaded** with **no assembly/collection parallelism** (same values as `Tst/xunit.runner.explicit.json`).
38+
39+
**One-shot command (from `Source`, after a Release build):**
40+
41+
```cmd
42+
dotnet test KZDev.PerfUtils.sln -c Release --no-build --filter "TestMode=Explicit" -- xUnit.Explicit=only xUnit.MaxParallelThreads=1 xUnit.ParallelizeAssembly=false xUnit.ParallelizeTestCollections=false
43+
```
44+
45+
**bash** (keep the filter expression in quotes so the shell does not treat `=` specially):
46+
47+
```bash
48+
dotnet test KZDev.PerfUtils.sln -c Release --no-build --filter "TestMode=Explicit" -- xUnit.Explicit=only xUnit.MaxParallelThreads=1 xUnit.ParallelizeAssembly=false xUnit.ParallelizeTestCollections=false
49+
```
50+
51+
**Notes:**
52+
53+
- Do **not** pass xUnit query filters such as `--filter-query /[TestMode=Explicit]` after `--` with this VSTest setup; the leading `/` is treated like a runsettings token and triggers **“invalid token”** errors. Prefer the `--filter` + `xUnit.*` form above.
54+
- **CI parity (optional):** To match the workflow that copies `Tst/xunit.runner.explicit.json` over each test output `xunit.runner.json`, run a **Release** `dotnet build` first, then copy that file onto every `artifacts/bin/*/release_net*/xunit.runner.json` under the repo root, then run the same `dotnet test` line **including** `--filter "TestMode=Explicit"` and `-- xUnit.Explicit=only` (the copy adjusts parallelism; the filter + `Explicit=only` still selects and runs explicit tests).
55+
56+
**Optional stricter host parallelism:** To cap VSTest process parallelism as well, copy `KZDev.PerfUtils.tests.runsettings` to a local file, set `<MaxCpuCount>1</MaxCpuCount>` under `<RunConfiguration>`, and add `dotnet test ... --settings path\to\your.runsettings`. Session timeout and other settings can stay aligned with the checked-in runsettings.
57+
58+
---
59+
60+
## Trait convention for new Explicit tests
61+
62+
Add **`[Trait(TestConstants.TestTrait.TestMode, TestConstants.TestMode.Explicit)]`** (or the string literals **`TestMode`** / **`Explicit`**) alongside **`[Fact(Explicit = true)]`** so Explicit-only runs remain discovery-based across assemblies that share source files.
63+
64+
---
65+
66+
## Linux: Docker-based test run
267

368
> Run these commands from the \{RepositoryRoot\}\Source directory
469
5-
## Build the image from the Dockerfile
70+
### Build the image from the Dockerfile
671

772
```cmd
873
docker build -t perfutils-linux-tests -f linuxtest.dockerfile .
974
```
1075

11-
## Create a host machine folder for the test results
76+
### Create a host machine folder for the test results
1277

1378
This folder will be used to store the test results from the container so you can review them later.
1479

@@ -18,20 +83,19 @@ mkdir {/path/to/host/machine/folder}
1883

1984
> Replace _\{/path/to/host/machine/folder\}_ with the path to the folder on the host machine you want to store the test result files in.
2085
21-
## Run the container from the image
86+
### Run the container from the image
2287

2388
This will run the tests and store the results in the folder you created in the previous step.
2489

2590
```cmd
2691
docker run --rm -v {/path/to/host/machine/folder}://app/Tst/linux-tests-results perfutils-linux-tests
2792
```
2893

29-
## Review the test results
94+
### Review the test results
3095

3196
The test result files are stored in the folder you specified in the previous step (\{/path/to/host/machine/folder\}) in xUnit XML format.
3297

33-
34-
## Cleanup the image when done with tests
98+
### Cleanup the image when done with tests
3599

36100
Keep your environment clean by removing the image when you are done running tests.
37101

0 commit comments

Comments
 (0)