-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Move xUnit tests in new folder #8356
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
Changes from all commits
6fe441b
664131d
d881c3a
2f5182f
c4a86e5
ca3243d
422ebf2
f6512de
d74fa5b
3e6fc6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add copyright header.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still missing copyright header here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I lost new commits. Fixed. |
||
|
|
||
| [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
| public class TestPriorityAttribute : Attribute | ||
| { | ||
| public TestPriorityAttribute(int priority) | ||
| { | ||
| Priority = priority; | ||
| } | ||
|
|
||
| public int Priority { get; private set; } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add copyright header.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Xunit.Abstractions; | ||
| using Xunit.Sdk; | ||
|
|
||
| namespace TestOrder.TestCaseOrdering | ||
| { | ||
| public class PriorityOrderer : ITestCaseOrderer | ||
| { | ||
| public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases) where TTestCase : ITestCase | ||
| { | ||
| var sortedMethods = new SortedDictionary<int, List<TTestCase>>(); | ||
|
|
||
| foreach (TTestCase testCase in testCases) | ||
| { | ||
| int priority = 0; | ||
|
|
||
| foreach (IAttributeInfo attr in testCase.TestMethod.Method.GetCustomAttributes((typeof(TestPriorityAttribute).AssemblyQualifiedName))) | ||
| priority = attr.GetNamedArgument<int>("Priority"); | ||
|
|
||
| GetOrCreate(sortedMethods, priority).Add(testCase); | ||
| } | ||
|
|
||
| foreach (var list in sortedMethods.Keys.Select(priority => sortedMethods[priority])) | ||
| { | ||
| list.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod.Method.Name, y.TestMethod.Method.Name)); | ||
| foreach (TTestCase testCase in list) | ||
| yield return testCase; | ||
| } | ||
| } | ||
|
|
||
| static TValue GetOrCreate<TKey, TValue>(IDictionary<TKey, TValue> dictionary, TKey key) where TValue : new() | ||
| { | ||
| TValue result; | ||
|
|
||
| if (dictionary.TryGetValue(key, out result)) return result; | ||
|
|
||
| result = new TValue(); | ||
| dictionary[key] = result; | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # xUnit Tests | ||
|
|
||
| The folder contains xUnit tests for PowerShell Core project. | ||
|
|
||
| ## Running xUnit Tests | ||
|
|
||
| Go to the top level of the PowerShell repository and run full set of tests: | ||
| `Start-PSxUnit` inside a self-hosted copy of PowerShell. | ||
|
|
||
| Go to the test project folder and run `dotnet test -c Release`. | ||
|
|
||
| Use [`filter`](xunit-filter) parameter to run only needed tests: | ||
| ```powershell | ||
| dotnet test -c Release --filter "FullyQualifiedName~UnitTest1 # Runs tests which have UnitTest1 in FullyQualifiedName | ||
| dotnet test --filter Name~TestMethod1 # Runs tests whose name contains TestMethod1 | ||
| ``` | ||
|
|
||
| ## Creating xUnit Tests | ||
|
|
||
| Keep the folder structure that is for Pester [../../test/powershell](../../test/powershell) and C# files [../../src](../../src). | ||
|
|
||
| Use namespace names started with `PSTests`. | ||
| ```c# | ||
| namespace PSTests.YourNameSpace | ||
| { | ||
| } | ||
| ``` | ||
|
|
||
| [xunit-filter]: https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,8 @@ public void TestRunspaceWithPowerShell() | |
| [Fact] | ||
| public void TestRunspaceWithPowerShellAndInitialSessionState() | ||
| { | ||
| InitialSessionState iss = InitialSessionState.CreateDefault2(); | ||
| // CreateDefault2 is intentional. | ||
| InitialSessionState iss = InitialSessionState.CreateDefault(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this changed?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two tests above use the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted with new comment.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adityapatwardhan that seems like a method name that probably needs revising, if we can, or adding an alias for in some fashion. Ilya is generally pretty familiar with the repo; if he got it confused, it's likely others will also.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the methodName would be a huge breaking change, but we could add a new method that calls this that is named better. I would suggest filing an issue about this. |
||
|
|
||
| // NOTE: instantiate custom host myHost for the next line to capture stdout and stderr output | ||
| // in addition to just the PSObjects | ||
|
|
@@ -90,9 +91,11 @@ public void TestRunspaceWithPowerShellAndInitialSessionState() | |
| ++objCount; | ||
| Assert.NotNull(result); | ||
| } | ||
|
|
||
| Assert.Equal(count, objCount); | ||
| powerShell.Dispose(); | ||
| } | ||
|
|
||
| runspace.Close(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| <PropertyGroup> | ||
| <Description>PowerShell xUnit Tests</Description> | ||
| <AssemblyName>powershell-tests</AssemblyName> | ||
| <GenerateProgramFile>true</GenerateProgramFile> | ||
|
||
| <RuntimeIdentifiers>win7-x86;win7-x64;osx-x64;linux-x64</RuntimeIdentifiers> | ||
| </PropertyGroup> | ||
|
|
||
|
|
@@ -26,5 +27,4 @@ | |
| <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" /> | ||
| <PackageReference Include="XunitXml.TestLogger" Version="2.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we validate if this is still the case. If not, we can removed the condition.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps @TravisEz13 can comment this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would have to try it to know.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could open a tracking issue for the work and don't block the PR.
Also we have many CodeFactor issues. Also we need to have more tests for binary APIs. Also we need to have performance tests. I think we should open new tracking issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done #8400