-
Notifications
You must be signed in to change notification settings - Fork 67
Testing #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
delatrie
wants to merge
121
commits into
main
Choose a base branch
from
testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,440
−60
Conversation
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.
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 dependency, build configuration, target framework, etc.
The flow
There are two types of the 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" requested by a test if hasn't been built yet.dotnet msbuild -t:Allure_BuildTestSamplesdotnet msbuild -t:Allure_RunTestSamplesdotnet run --project <Testing Project>On-demand flow
In on-demand flow, the sample projects run when explicitly demanded by a test. It may slightly vary, but typically looks like this:
dotnet run --project Allure.NUnit.Tests.dotnet testagainst the sample project.dotnet test.This flow allows to run a single test more quickly. On the other hand, running a bunch of tests may be way too slow as each requires to spin a new
dotnet testprocess. Additionally, the tests can't run in parallel because deparatedotnet testprocessed may conflict with each other when trying simultaneously rebuild common dependencies.For such scenarios, 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 expressed 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 Allure.NUnit.Tests --no-restore --no-buildSince no extra
dotnetprocesses are spinned, all tests in all test projects can run in parallel and the run is much faster in general.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 agaisnt multiple versions of .NET without creating extra jobs or while being on a developer's machine.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. Additionally, it setsAllure_PreRunTestingFlowtotrueunless it's defined at the CLI level or redefined at 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.One side effect is that
ProjectReferencecauses all transitive dependencies to be built ondotnet test(unless skipped by incremental build). Since such dependencies (likeAllure.Net.Commons) are shared by multiple sample projects, parallel execution of suchdotnet testcommands leds to conflicts on the file system level. That's why parallel test execution is disabled if aProjectReferenceitem is detected in the sample projects.The following properties affects 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 pack 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 name of the test project, 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 will look for Allure result files in pre-run flow.Closes #362.