Skip to content
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

UnitTests: Check if SDK version is installed and if not ignore the test #109

Merged
merged 4 commits into from
May 2, 2024

Conversation

obligaron
Copy link
Contributor

This PR changes the tests to be ignored/skipped, if the required SDKs/TargetFrameworks are not installed on the local machine.
This helps to improve the (first time) developer experience (at least for me 😉).

Before/After changes

Test CreateEmptyCSharpCore3_1ProjectInNewFormat

Before (main)

grafik

After (PR)

grafik

Test GeneratorAllIn_sample_can_be_handled

Before (main)

grafik

After (PR)

grafik

With this PR no tests fail on my machine (windows) even if not all SDKs/TargetFrameworks are installed.

If desired, we can disable this behaviour when running tests in CI to ensure that all relevant SDKs and frameworks are installed. (Currently not implemented.)

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • Performance improvement
  • Refactoring (so no functional change)
  • Other (docs, build config, etc)

Checklist:

  • I've added tests for my code. (most of the time mandatory)
  • I have added an entry to the changelog. (mandatory)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@gasparnagy
Copy link
Contributor

That is cool @obligaron. I was also thinking about something similar. Three questions:

  1. Isn't there an option in SystemTests (that uses MsTest) to check the exception that was thrown and do the dynamic ignore in the TestCleanup? (So that we don't have to do the try-catch on the tests) Maybe this info is in the TestContext somewhere...
  2. If that is not possible, maybe we can provide a method in the base class, that takes an Action parameter and wraps it with the try-catch. So that if we change that logic, we don't need to do it for each case.
  3. The ConfigurationDriver class provides a setting called PipelineMode, that is true when the tests run in the pipeline. Could we change the SystemTests in a way that it only does the dynamic ignore if it is running locally (so the PipelineMode is false). I fear that if something changes on our CI agent, we would not be modified about an untested framework.

@obligaron
Copy link
Contributor Author

I'm glad you like the idea. 🙂

Regarding your questions

  1. I added a new SkippableTestMethodAttribute' to mimic the behaviour of the SkippableFactAttribute'. Is this a good way to do this?
  2. I can also go this way if you don't like the SkippableTestMethodAttribute approach.
  3. I added the PiplineMode check for CompilationDriver related errors (last commit).
    But I wasn't sure how to access the property in SolutionWriter'. I couldn't find a member that contained a ConfigurationDriver. What would be a good way to access the information? So currently the PiplineMode` check is only half implemented (which is why I changed the PR to draft).

@obligaron obligaron marked this pull request as draft April 25, 2024 21:10
@gasparnagy
Copy link
Contributor

@obligaron this is all good. I did not know that you can make such fancy stuff with the TestMethodAttribute.

For the pipeline mode: My original idea was to add the condition to the SkippableXXX attribute, so you only change the outcome if no pipeline mode (maybe there will be other similar checks). There you can just create a new instance of the ConfigurationDriver there (and get the PipelineMode property), it does not have a dependency and it is cheap to create one.

If that does not work or if you prefer to do the checks in the TestProjectGenerator, you can do the check in the SolutionWriter (or any other class there, like the CompilationDriver), just simply add the ConfigurationDriver to the ctor and the DI will resolve it. You don't have to route it through the other classes.

@obligaron
Copy link
Contributor Author

I added ConfigurationDriver to SolutionWriter. 😉

But I would also be fine with doing the check in the test methods instead when the throw happens.
The only down-side is that I think we can't parametersize SkippableFact dynamically. We would need a Method that takes a action parameter and do the check (like you suggested in your first comment). If you prefer it that way I can change the PR to this approach. 🙂

@obligaron obligaron marked this pull request as ready for review April 28, 2024 19:11
@gasparnagy
Copy link
Contributor

@obligaron Thx.

You do not need to really make the SkippableFact parameterizable for this. The ConfigurationDriver is anyway reading this configuration from environment variables. So anywhere in the SkippableFact you can write things like:

if (! new ConfigurationDriver().PipelineMode) {
  //do the skipping
}

@obligaron
Copy link
Contributor Author

The test is now done in the UnitTest. 😉
Please take a look.

Copy link
Contributor

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@gasparnagy gasparnagy merged commit cd519f3 into reqnroll:main May 2, 2024
4 checks passed
@gasparnagy
Copy link
Contributor

@obligaron Thx. I have invited you to the contributors team (you need to accept the invitation). Being in this team means that the CI build will automatically run for your PRs and that you can create new branches in the main repo. This latter means that if you would like to contribute with a change, you don't need to fork the Reqnroll project (or sync your fork), but you can simply clone the main repository, create a new branch, push that up and create a PR for that branch. This also has the benefits, that others can help you with code changes in your PR just by adding commits to that branch.

@obligaron
Copy link
Contributor Author

Thanks @gasparnagy 🙂

@obligaron obligaron deleted the sdkcheck branch May 2, 2024 16:46
gasparnagy added a commit that referenced this pull request May 22, 2024
…ons-dependencyinjection-plugin

* origin/main: (21 commits)
  Fix #56 autofac ambiguous stepdef and hook required #127 issue (#139)
  Reduce target framework of Reqnroll to netstandard2.0 (#130)
  Fix StackOverflowException when using [StepArgumentTransformation] with same input and output type (#136)
  MsTest: Replace DelayedFixtureTearDown special case with ClassCleanupBehavior.EndOfClass (#128)
  Temporarily disabled tests until #132 is resolved
  Add NUnit & xUnit core tests to portability suite
  Capture ExecutionContext after every binding invoke (#126)
  small improvement in CodeDomHelper to be able to chain async calls
  fix method name sources in UnitTestFeatureGenerator
  External data plugin, support for JSON files  (#118)
  UnitTests: Check if SDK version is installed and if not ignore the test (#109)
  Fix 111 ignore attr not inherited from rule (#113)
  Update README.md (#110)
  Fix 81 - modified CucumberExpressionParameterTypeRegistry to handle multiple custom types used as cucumber expressions when those types share the same short name. (#104)
  Update index.md
  Simplify test project targets (#105)
  Make SystemTests temp folder configurable and use NUGET_PACKAGES env var to override global NuGet folder
  Fleshing out Generation System Tests (2) (#99)
  Fix for 81 - Cucumber Expression using Enums errors when two enums exist with the same short name (#100)
  Include BoDi to Reqnroll package (#91) (#95)
  ...

# Conflicts:
#	Reqnroll.sln
#	Tests/Reqnroll.PluginTests/Reqnroll.PluginTests.csproj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants