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

Update test project to use MSTest #3694

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion test/IntegrationTests/MSTest.IntegrationTests/ClsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.MSTestV2.CLIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest.IntegrationTests;

[TestClass]
public class ClsTests : CLITestBase
{
private const string TestAssetName = "ClsTestProject";

// This test in itself is not so important. What matters is that the asset gets build. If we regress and start having
// the [DataRow] attribute no longer CLS compliant, the build will raise a warning in VS (and the build will fail in CI).
// the [DataRow] attribute no longer CLS compliant, the build will raise a warning in VS (and the build will fail in CI.)
[TestMethod]
public void TestsAreRun()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.MSTestV2.CLIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest.IntegrationTests;

[TestClass]
public class DiscoverInternalsTests : CLITestBase
{
private const string TestAsset = "DiscoverInternalsProject";

[TestMethod]
public void InternalTestClassesAreDiscoveredWhenTheDiscoverInternalsAttributeIsPresent()
{
// Arrange
Expand All @@ -25,6 +28,7 @@ public void InternalTestClassesAreDiscoveredWhenTheDiscoverInternalsAttributeIsP
"NestedInternalClass_TestMethod1");
}

[TestMethod]
public void AnInternalTestClassDerivedFromAPublicAbstractGenericBaseClassForAnInternalTypeIsDiscovered()
{
// Arrange
Expand All @@ -39,6 +43,7 @@ public void AnInternalTestClassDerivedFromAPublicAbstractGenericBaseClassForAnIn
"EqualityIsCaseInsensitive");
}

[TestMethod]
public void AnInternalTypeCanBeUsedInADynamicDataTestMethod()
{
string assemblyPath = Path.IsPathRooted(TestAsset) ? TestAsset : GetAssetFullPath(TestAsset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.MSTestV2.CLIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest.IntegrationTests;

[TestClass]
public class FSharpTestProjectTests : CLITestBase
{
private const string TestAssetName = "FSharpTestProject";

[TestMethod]
public void TestFSharpTestsWithSpaceAndDotInName()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>$(NetFrameworkMinimum)</TargetFramework>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn),1685</NoWarn>
<OutputType>Exe</OutputType>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,8 +19,19 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)test\Utilities\TestFramework.ForTestingMSTest\TestFramework.ForTestingMSTest.csproj" />
<ProjectReference Include="$(RepoRoot)src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj" />
<ProjectReference Include="$(RepoRoot)src\TestFramework\TestFramework\TestFramework.csproj" />
<ProjectReference Include="$(RepoRoot)src\Analyzers\MSTest.Analyzers\MSTest.Analyzers.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" SetTargetFramework="TargetFramework=netstandard2.0" />
<ProjectReference Include="$(RepoRoot)src\Analyzers\MSTest.Analyzers.CodeFixes\MSTest.Analyzers.CodeFixes.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" SetTargetFramework="TargetFramework=netstandard2.0" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\Microsoft.Testing.Platform.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.TrxReport.Abstractions\Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.TrxReport\Microsoft.Testing.Extensions.TrxReport.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="MSTest.IntegrationTests.testconfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"platformOptions": {
"telemetry": {
"isDevelopmentRepository": true
},
"exitProcessOnUnhandledException": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest.IntegrationTests;

[TestClass]
public class NoNamespaceTests : CLITestBase
{
private const string TestAssetName = "HierarchyProject";

[TestMethod]
public void TestsAreDiscoveredWithExpectedHierarchy()
{
// Arrange & Act
Expand Down
5 changes: 5 additions & 0 deletions test/IntegrationTests/MSTest.IntegrationTests/OutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@

using Microsoft.MSTestV2.CLIAutomation;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using TestResult = Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult;

namespace MSTest.IntegrationTests;

public class OutputTests : CLITestBase
{
private const string TestAssetName = "OutputTestProject";

[TestMethod]
public void OutputIsNotMixedWhenTestsRunInParallel() => ValidateOutputForClass("UnitTest1");

[TestMethod]
public void OutputIsNotMixedWhenAsyncTestsRunInParallel() => ValidateOutputForClass("UnitTest2");

private void ValidateOutputForClass(string className)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.MSTestV2.CLIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest.IntegrationTests;

[TestClass]
public class DataExtensibilityTests : CLITestBase
{
private const string TestAssetName = "FxExtensibilityTestProject";
Expand All @@ -15,6 +17,7 @@ public class DataExtensibilityTests : CLITestBase
- Ignored tests are not expanded (DataRow, DataSource, etc)
*/

[TestMethod]
public void CustomTestDataSourceTests()
{
// Arrange
Expand All @@ -28,6 +31,7 @@ public void CustomTestDataSourceTests()
VerifyE2E.ContainsTestsPassed(testResults, "CustomTestDataSourceTestMethod1 (1,2,3)", "CustomTestDataSourceTestMethod1 (4,5,6)");
}

[TestMethod]
public void AssertExtensibilityTests()
{
// Arrange
Expand All @@ -42,6 +46,7 @@ public void AssertExtensibilityTests()
VerifyE2E.ContainsTestsFailed(testResults, "BasicFailingAssertExtensionTest", "ChainedFailingAssertExtensionTest");
}

[TestMethod]
public void ExecuteCustomTestExtensibilityTests()
{
// Arrange
Expand Down Expand Up @@ -69,6 +74,7 @@ public void ExecuteCustomTestExtensibilityTests()
"CustomTestClass1 - Execution number 3");
}

[TestMethod]
public void ExecuteCustomTestExtensibilityWithTestDataTests()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.MSTestV2.CLIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest.IntegrationTests;

[TestClass]
public class DataRowTests : CLITestBase
{
private const string TestAssetName = "DataRowTestProject";

[TestMethod]
public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerivedClassHasDataRows_SimpleDataRows()
{
// Arrange
Expand All @@ -28,6 +31,7 @@ public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerivedClassHasDataRow
"DataRowTestMethod (\"DerivedString2\")");
}

[TestMethod]
public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_SimpleDataRows()
{
// Arrange
Expand All @@ -44,6 +48,7 @@ public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_Simp
"DataRowTestMethod (\"DerivedString2\")");
}

[TestMethod]
public void DataRowsExecuteWithRequiredAndOptionalParameters()
{
// Arrange
Expand All @@ -61,6 +66,7 @@ public void DataRowsExecuteWithRequiredAndOptionalParameters()
"DataRowTestMethodWithSomeOptionalParameters (123,\"DerivedOptionalString2\",\"DerivedOptionalString3\")");
}

[TestMethod]
public void DataRowsExecuteWithParamsArrayParameter()
{
// Arrange
Expand All @@ -79,6 +85,7 @@ public void DataRowsExecuteWithParamsArrayParameter()
"DataRowTestMethodWithParamsParameters (2,\"DerivedParamsArg1\",\"DerivedParamsArg2\",\"DerivedParamsArg3\")");
}

[TestMethod]
public void DataRowsFailWhenInvalidArgumentsProvided()
{
// Arrange
Expand All @@ -96,6 +103,7 @@ public void DataRowsFailWhenInvalidArgumentsProvided()
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");
}

[TestMethod]
public void DataRowsShouldSerializeDoublesProperly()
{
// Arrange
Expand All @@ -112,6 +120,7 @@ public void DataRowsShouldSerializeDoublesProperly()
"DataRowTestDouble (10.02,20.02)");
}

[TestMethod]
public void DataRowsShouldSerializeMixedTypesProperly()
{
// Arrange
Expand All @@ -127,6 +136,7 @@ public void DataRowsShouldSerializeMixedTypesProperly()
"DataRowTestMixed (10,10,10,10,10,10,10,\"10\")");
}

[TestMethod]
public void DataRowsShouldSerializeEnumsProperly()
{
// Arrange
Expand All @@ -145,6 +155,7 @@ public void DataRowsShouldSerializeEnumsProperly()
"DataRowEnums (Gamma)");
}

[TestMethod]
public void DataRowsShouldHandleNonSerializableValues()
{
// Arrange
Expand All @@ -166,6 +177,7 @@ public void DataRowsShouldHandleNonSerializableValues()
"DataRowNonSerializable (DataRowTestProject.DataRowTests_DerivedClass)");
}

[TestMethod]
public void ExecuteDataRowTests_Enums()
{
// Arrange
Expand Down Expand Up @@ -241,6 +253,7 @@ public void ExecuteDataRowTests_Enums()
VerifyE2E.FailedTestCount(testResults, 0);
}

[TestMethod]
public void ExecuteDataRowTests_NonSerializablePaths()
{
// Arrange
Expand All @@ -259,6 +272,7 @@ public void ExecuteDataRowTests_NonSerializablePaths()
VerifyE2E.FailedTestCount(testResults, 0);
}

[TestMethod]
public void ExecuteDataRowTests_Regular()
{
// Arrange
Expand Down Expand Up @@ -320,6 +334,7 @@ public void ExecuteDataRowTests_Regular()
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");
}

[TestMethod]
public void GetDisplayName_AfterOverriding_GetsTheNewDisplayName()
{
// Arrange
Expand All @@ -334,6 +349,7 @@ public void GetDisplayName_AfterOverriding_GetsTheNewDisplayName()
"Overridden DisplayName");
}

[TestMethod]
public void ParameterizedTestsWithTestMethodSettingDisplayName_DataIsPrefixWithDisplayName()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.MSTestV2.CLIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest.IntegrationTests;

[TestClass]
public class DataSourceTests : CLITestBase
{
private const string TestAssetName = "DataSourceTestProject";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.MSTestV2.CLIAutomation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MSTest.IntegrationTests;

[TestClass]
public class DynamicDataTests : CLITestBase
{
private const string TestAssetName = "DynamicDataTestProject";

[TestMethod]
public void ExecuteDynamicDataTests()
{
// Arrange
Expand Down Expand Up @@ -56,6 +59,7 @@ public void ExecuteDynamicDataTests()
VerifyE2E.FailedTestCount(testResults, 0);
}

[TestMethod]
public void ExecuteDynamicDataTestsWithCategoryFilter()
{
// Arrange
Expand Down
22 changes: 22 additions & 0 deletions test/IntegrationTests/MSTest.IntegrationTests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Reflection;

using Microsoft.Testing.Platform.Builder;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.MethodLevel)]

// To attach to the children
// Microsoft.Testing.TestInfrastructure.DebuggerUtility.AttachCurrentProcessToParentVSProcess();
ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
testApplicationBuilder.AddMSTest(() => [Assembly.GetEntryAssembly()!]);

// Enable Trx
// testApplicationBuilder.AddTrxReportProvider();

// Enable Telemetry
// testApplicationBuilder.AddAppInsightsTelemetryProvider();
using ITestApplication testApplication = await testApplicationBuilder.BuildAsync();
return await testApplication.RunAsync();
Loading
Loading