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

Change Apex tests from Xunit to MSTest #5428

Merged
merged 26 commits into from
Oct 3, 2023

Conversation

heng-liu
Copy link
Contributor

@heng-liu heng-liu commented Sep 27, 2023

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/2379

Regression? Last working version:

Description

Background
MSTest is able to time out individual Apex test, and it could attach files for diagnosing the flakiness. So we decided to migrate Apex test from Xunit to MSTest.

1.Change Apex test from Xunit to MSTest:

  • Change Xunit attributes to MSTest attributes: Theory -> TestMethod, InlineData -> DataRow, Skip -> Ignore, etc.
  • Add Timeout attribute for each Apex tests
  • Change Xunit.Assert to MSTest assertion
  • Adapt setup of Xunit (fixture) to MSTest setup (ClassInitialize). (MSTest has limitation as ClassInitialize is not inheritable. So change the previous fixture for base test class to a static property.) -- This seems get fixed in a newer version of MS packages.
  • Change logger into ITestLogger and follow the suggestions in the wiki.
  1. Engineering change
  • Add MSTest packages: MSTest.TestAdapter and MSTest.TestFramework
  • Change build/template.runsettingsproj to add console logger, so that trace will be shown in the log.
  • Clean up test/NuGet.Tests.Apex/NuGet.Tests.Apex/xunit.runner.json
  • Clean up project test/TestExtensions/NuGet.StaFact

In the recent 11 runs, the Apex tests passed 8 times.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@zivkan
Copy link
Member

zivkan commented Sep 28, 2023

OMG! The pipeline didn't timeout, and other tests actually ran!!!

image

Copy link
Contributor

@dtivel dtivel left a comment

Choose a reason for hiding this comment

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

Overall, it looks good. Thanks, @heng-liu!

@@ -22,12 +21,15 @@ public class IVsServicesTestCase : SharedVisualStudioHostTestClass, IClassFixtur

private readonly SimpleTestPathContext _pathContext = new SimpleTestPathContext();

public IVsServicesTestCase(VisualStudioHostFixtureFactory visualStudioHostFixtureFactory, ITestOutputHelper output)
: base(visualStudioHostFixtureFactory, output)
private const int Timeout = 5 * 60 * 1000; // 5 minutes
Copy link
Contributor

Choose a reason for hiding this comment

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

We can move this to a shared location as a global default and reuse it everywhere, instead of redefining Timeout in every test class. On a case-by-case basis, we can override the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Moved it to test/NuGet.Tests.Apex/NuGet.Tests.Apex/Apex/SharedVisualStudioHostTestClass.cs

@heng-liu heng-liu marked this pull request as ready for review October 2, 2023 15:55
@heng-liu heng-liu requested a review from a team as a code owner October 2, 2023 15:55
@heng-liu heng-liu requested a review from dtivel October 2, 2023 16:00
Copy link
Contributor

@jeffkl jeffkl left a comment

Choose a reason for hiding this comment

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

Great work on this!

@heng-liu heng-liu merged commit 6a096d0 into dev Oct 3, 2023
@heng-liu heng-liu deleted the dev-hengliu-CI-changeApex-mstest-enableAllApex-test branch October 3, 2023 18:03
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.

4 participants