Conversation
This reverts commit 8cd52b6.
epszaw
approved these changes
Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This PR sets up a testing infrastructure for allure-csharp packages. It also includes a set of Allure.NUnit tests to verify the infrastructure.
FAQ
How to create a test project?
Use
Allure.NUnit.Testsas a reference.SamplePackageReferenceitems to add package references to all samples.ProjectUnderTestitem to link samples to the target project/package.tests/Allure.Testing/Allure.Testing.csproj.build/Allure.Build.SourceGenerators/Allure.Build.SourceGenerators.csprojwithOutputItemType="Analyzer"andReferenceOutputAssembly="false".ALLURE_TEST_PARALLELsymbol with the conditional compilation directives to enable the parallel execution of the test. See./tests/Allure.NUnit.Tests/GlobalSetup.csfor an example. SeeHow to run the tests in parallel?below for more details.How to create and use a single-file sample?
./Samples/directory of the project. Write the code of the sample.Allure.Testing.AllureSampleRegistry.<Sample ID>toAllure.Testing.AllureSampleRunner.RunAsync.Sample IDis the name of the file without extension.How to create and use a multi-file sample?
./Samples/. Put the files inside the folder.Allure.Testing.AllureSampleRegistry.<Sample ID>toAllure.Testing.AllureSampleRunner.RunAsync.Sample IDis the name of the folder you've created at step 1.How to run a test project?
Use
dotnet run --project ./tests/<project-name>.How to test against a NuGet package?
By default, the samples use project references to access the tested functionality. If you would like to use package references instead, use the
Allure_TestTargetVersionMSBuild property:This will run the tests against a published NuGet package. To test a dev version, set the property to
SNAPSHOT:This will run the tests against the current SNAPSHOT version of the package in the local repository (
./artifacts/package/releaseby default). Don't forget to rundotnet pack --configuration Releaseto create or update the packages first. If you've just updated the packages, you might need to clear the cache before running the test:What is pre-run flow?
Pre-run flow separates the samples run from the tests run. First, all the samples are run together. Then the tests verify the results. This greatly reduces the total time of test runs.
The easiest way to utilize the flow is to set the
Allure_PreRunTestSamplesMSBuild property totrue:The command will update and run all the test project's samples. It will then run the project itself.
Allure.Testing.AllureSampleRunnerdetects this setup. Instead of executing the sample, it will read the already available results and return them.How to test against the dev version of a NuGet package with pre-run flow?
First, build and pack the packages:
Next, make sure the packages cache is clean:
Finally, run the test project with both
Allure_PreRunTestSamplesandAllure_TestTargetVersionset:How to run the tests in parallel?
By default, all tests are sequential. This is because the tests issue
dotnet testcommands against sample projects with shared project references (mainly, toAllure.Net.Commons). This can cause conflicts between parallel builds of the same dependency project.To run the tests in parallel, use one of the following options:
Allure_TestTargetVersion(seeHow to test against a NuGet package?above). In such a case, the samples will use package references instead of project references. No project references means no shared dependency projects to build.Allure_PreRunTestSamplesis set totrueduring the test project build (which also happens ondotnet run), the test project will assume nodotnetprocesses need to be run as the results must be available when the tests run. This doesn't give much, though, since in pre-run flow, the tests only run assertions, which are very fast even when run sequentially.Note
In order for this to work, the test project must enable the parallel execution if and only if the
ALLURE_TEST_PARALLELsymbol is defined. This is how./tests/Allure.NUnit.Testsdoes this (./tests/Allure.NUnit.Tests/GlobalUsing.cs)How to build the samples of a test project without building the project?
How to clean the sample projects?
or
How to clean the sample solutions and their output?
The testing scheme
Here is the testing scheme that includes the testing infrastructure, a test project, a target project/package, a set of external dependencies, and temporary artefacts generated by the infrastructure.
Sample projects are fully decoupled from tests. They have their own dependencies, build configurations, target frameworks, etc.
The key elements
GenerateSampleSolution- an MSBuild task that creates or updates a sample solution for a test project. It only writes files that have been changed. This keeps incremental builds.andclasses in./build/Allure.Build.SourceGenerators, which are Roslyn source generators. Their job is to keep the sample registry up to date with the actual set of samples in the project.AllureSampleRegistry- a class generated by a source generator. It exposes a set of static properties, each representing a sample project that can be run. The job of the class is to make sample execution type safe.AllureSampleRunner- a class defined in./tests/Allure.Testing. Contains a couple ofRunAsyncoverloads for executing test samples. In the pre-run mode, it only reads the result directory.The flow
There are two types of flow: on-demand and pre-run, each consisting of four phases. Each phase can be run manually. Some are run automatically.
dotnet msbuild -t:Allure_GenerateTestSamplesAllure_PreBuildTestSamplesistrue. Right before "Run" is requested by a test if the sample project is out of date.dotnet msbuild -t:Allure_BuildTestSamplesdotnet msbuild -t:Allure_RunTestSamplesdotnet run --project <Testing Project>On-demand flow
In the on-demand flow, sample projects run only when explicitly requested by a test. It may slightly vary, but it typically looks like this:
dotnet run --project ./tests/Allure.NUnit.Tests.dotnet testagainst the sample project.dotnet test.This flow allows a single test to run more quickly. On the other hand, running a bunch of tests may be way too slow as each requires spinning a new
dotnet testprocess. Additionally, the tests can't run in parallel because separatedotnet testprocesses may conflict when trying to rebuild common dependencies.For such scenarios, a pre-run flow was designed.
Pre-run flow
Pre-run flow implies running all the samples in advance. The tests are only asserting the already prepared results. This can be performed during the development, but the primary goal of this flow is to speed up the CI pipeline. The flow looks like this:
dotnet run --project Allure.NUnit.Tests -p:Allure_PreRunTestSamples=truedotnet test. Instead, it reads the default results directory. If it exists and contains result files, the results are returned to the test. Otherwise, the runner throws an error.In a CI pipeline, a more expressive version can be used to test against the default configuration and .NET version:
dotnet restoredotnet build --no-restore -p:Allure_PreRunTestingFlow=true -p:Allure_PreBuildTestSamples=truedotnet msbuild -t:Allure_RunTestSamplesdotnet run --project ./tests/Allure.NUnit.Tests --no-restore --no-buildTesting packed projects
The same set of tests defined in a test project can be run against a NuGet package (either published or dev version).
To test against a dev version, it needs to be built and packed first:
Next, make sure an old version is not cached:
Now, run the tests against the dev (snapshot) version:
To test against a published version, set
Allure_TestTargetVersionto this version:Test projects that target NuGet packages will run their tests in parallel (if they followed the recommendations from the FAQ, see
How to run the tests in parallel?.Sample lifecycle targets
Use the following MSBuild targets to control the sample lifecycle:
Allure_GenerateTestSamples- creates/updates the sample solutions.Allure_BuildTestSamples- restores and builds the sample solutions.Allure_RunTestSamples- executed the tests defined by projects of the sample solutions.Allure_CleanTestSamples- runs theCleantarget against the sample solutions. This also cleans the default results directory.Allure_DeleteTestSamples- deletes sample solutions with all intermediate and output directories of their projects.MSBuild properties and items
The following items need to be defined for each testing project:
SamplePackageReference: each item will be converted to aPackageVersionitem in the sample solution'sDirectory.Packages.props. Additionally, each item will be converted to aPackageReferencefor every sample project, unlessOptionalis set totrue.Supported metadata:
Directory.Packages.props. It won't be added to a sample project's package references.ProjectUnderTest: each item will be converted to aProjectReferenceof aPackageReferencefor all sample projects, depending on the value of theAllure_TestTargetVersionproperty:Allure_TestTargetVersionis unset,ProjectUnderTestbecomesProjectReference.ProjectUnderTestbecomesPackageReferencewithVersionset toAllure_TestTargetVersion. A special valueSNAPSHOTindicates the current version ($(Version)).The motivation is to allow testing against a packed version of the target project (including already published versions).
The following properties can be used to tune the testing process:
Allure_SampleSupportedTargetFrameworks: the list of target frameworks the sample projects can be compiled against. By default, the list includes one current TFM (as of today, it'snet8.0). The motivation is to allow testing across multiple .NET versions without creating extra jobs.This property only affects the generation phase.
Allure_PreBuildTestSamples: if set totrue, the sample solution will be restored and built right after the generation.This property only affects the generation phase.
Allure_PreRunTestSamples: if set totrue, the sample solution will be restored, built, and tested right after the generation (which happens automatically during the test project's build). Additionally, it setsAllure_PreRunTestingFlowtotrueunless it's defined at the CLI level or redefined at the project level.This property only affects the generation phase.
Allure_PreRunTestingFlow: if set totrue, enables the pre-run flow. This property affects the generation and execution phases.Allure_SampleSelectedTargetFramework: a specific TFM to run the samples against. If not set, the samples are run against each TFM in theAllure_SampleSupportedTargetFrameworkslist.This property only affects the execution phase.
Allure_SampleConfiguration: a specific configuration used to build the sample projects.This property only affects the build phase.
Allure_TestTargetVersion: if set, the sample projects reference the target as a NuGet package of the specified version. A special valueSNAPSHOTindicated the current development version. In such a case, the package must exist in the local repository pointed byAllure_LocalNugetRepositorybefore the sample solution is built. If unset, the sample projects reference the target viaProjectReferenceitems.The following properties affect the testing but have default values, and it's unlikely someone needs to change them:
Allure_LocalNugetRepository: a path to the local NuGet repository that contains unpublished packages (like SNAPSHOT packages).Allure_PackageCacheDirectory: a path to the package cache directory. By default, it's./packages/. The motivation is to ensure SNAPSHOT packages don't pollute the system-wide cache.Allure_SampleSolutionName: a name of the sample solution. By default, it's the test project's name, suffixed with.Samples.Allure_SampleSolutionDir: a directory of the sample solution. By default, it's./artifacts/samples/<test project>.Allure_SampleResultsDirectoryFormat: a format string that has one{0}placeholder for the sample ID. When the ID is inserted, it must give the absolute path to a directory. This directory is where the sample runner looks for Allure result files during the pre-run flow.AllureSampleitemsAllureSampleitems is that drive the generation of sample projects. Each test project generates exactly one sample solution, which contains multiple sample projects. Each sample project has one or more files, each represented by anAllureSampleitem of the test project.By default, the items include
Samples/**/*files inside a test project. The top-level entries in theSamplesdirectory become sample projects. If the entry is a file, it will be copied right into the sample project directory. If the entry is a directory, all files in that directory will be copied to the sample project directory, preserving relative paths.The name of the sample project is
$(Allure_SampleSolutionName).$(ProjectSuffix), whereProjectSuffixis the name of the corresponding top-level entry in./Samples/without extension. For example,ProjectSuffixofSamples/Foo.csisFoo, whileProjectSuffixofSamples/Bar/Baz.csisBar.To overwrite
ProjectSuffix, use theUpdateattribute on the item:Closes #362.