Skip to content

Add tests for test templates #49102

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
May 23, 2025

Conversation

mariam-abdulla
Copy link
Member

@mariam-abdulla mariam-abdulla commented May 22, 2025

This pull request introduces a new test suite for validating .NET project and item templates in the test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs file. The changes include adding comprehensive tests for template installation, compatibility across languages, and integration with testing platforms.

Additions to Template Testing:

Utility Enhancements:

  • Helper Methods:
    • AddItemToFsproj: Handles adding F# items to `.fsproj

@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 08:19
@mariam-abdulla mariam-abdulla requested a review from a team as a code owner May 22, 2025 08:19
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new integration test for handling incorrect host data in template installations.

  • Introduces an additional test case to verify installation exit code when host data is incorrect.
  • Uses a custom hive and working directory for isolation in the new test.
Comments suppressed due to low confidence (2)

test/dotnet-new.IntegrationTests/DotnetNewInstallTests.cs:608

  • The test method name ends with '1', which is ambiguous. Consider renaming it to reflect the specific scenario being tested, e.g., CanInstall_WhenHostDataIsIncorrect.
public void CanShowWarning_WhenHostDataIsIncorrect1()

test/dotnet-new.IntegrationTests/DotnetNewInstallTests.cs:615

  • This assertion only checks the exit code. To fully validate the behavior for incorrect host data, add assertions for expected warning messages in stdout or stderr.
.Should().ExitWith(0);

@mariam-abdulla mariam-abdulla enabled auto-merge (squash) May 22, 2025 14:27

private static readonly ImmutableArray<string> SupportedTargetFrameworks =
[
"net10.0",
Copy link
Member

Choose a reason for hiding this comment

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

Did you want to target any downlevel versions? In net11, would these tests target net11 and net10 or be updated to just net11? If you're only ever going to target current, you might be able to reuse the values in ToolsetInfo.cs so as to reduce the work needed when upgrading TFMs.

];

private static readonly (string ProjectTemplateName, string ItemTemplateName, string[] Languages, bool SupportsTestingPlatform)[] AvailableItemTemplates =
[
Copy link
Member

Choose a reason for hiding this comment

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

How will you make sure you add any new ones here that get added in the future? Is this going to be documented somewhere?

static DotnetNewTestTemplatesTests()
{
string templatePackagePath = Path.Combine(
RepoTemplatePackages,
Copy link
Member

Choose a reason for hiding this comment

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

You've confirmed that this is the live location in the build, correct? I think it is but just double checking it's not the stage 0 (global.json) one as that version of templates is usually a month behind.


var dummyLog = new NullTestOutputHelper();

new DotnetNewCommand(dummyLog, "uninstall", templatePackagePath)
Copy link
Member

Choose a reason for hiding this comment

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

Help me understand why you uninstall first? Just to ensure the install works if it was already installed?

.WithCustomHive(CreateTemporaryFolder(folderName: "Home"))
.WithWorkingDirectory(CreateTemporaryFolder())
.Execute()
.Should().ExitWith(0);
Copy link
Member

Choose a reason for hiding this comment

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

nit: Can use .Pass() to be a bit more obvious

.WithCustomHive(outputDirectory).WithRawArguments()
.WithWorkingDirectory(workingDirectory)
.Execute()
.Should().ExitWith(0);
Copy link
Member

Choose a reason for hiding this comment

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

same nit on Pass()

.WithCustomHive(outputDirectory).WithRawArguments()
.WithWorkingDirectory(workingDirectory)
.Execute()
.Should().ExitWith(0);
Copy link
Member

Choose a reason for hiding this comment

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

same nit

result.Should().ExitWith(0);

result.StdOut.Should().Contain("Passed!");
result.StdOut.Should().MatchRegex(@"Passed:\s*2");
Copy link
Member

Choose a reason for hiding this comment

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

There are two tests that run?

@mariam-abdulla mariam-abdulla merged commit d9960a9 into main May 23, 2025
30 checks passed
@mariam-abdulla mariam-abdulla deleted the dev/mabdullah/create-tests-for-test-templates branch May 23, 2025 21:40
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants