Add more tests for parameterized tests (#1330)

This commit is contained in:
Amaury Levé 2022-10-11 14:52:56 +02:00 коммит произвёл GitHub
Родитель 9a4c30e079
Коммит fc6680bb2a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
27 изменённых файлов: 697 добавлений и 445 удалений

Просмотреть файл

@ -188,7 +188,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Net6", "Net6", "{35D010CC-C
src\Adapter\Build\Net6\MSTest.TestFramework.targets = src\Adapter\Build\Net6\MSTest.TestFramework.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReferencedProjectFromDataSourceTest", "test\E2ETests\TestAssets\ReferencedProjectFromDataSourceTest\ReferencedProjectFromDataSourceTest.csproj", "{6B4DE65C-4162-4C52-836A-8F9FA901814A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibProjectReferencedByDataSourceTest", "test\E2ETests\TestAssets\LibProjectReferencedByDataSourceTest\LibProjectReferencedByDataSourceTest.csproj", "{6B4DE65C-4162-4C52-836A-8F9FA901814A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscoverInternalsProject", "test\E2ETests\TestAssets\DiscoverInternalsProject\DiscoverInternalsProject.csproj", "{44A504D9-A0D6-427D-BFB2-DB144A74F0D5}"
EndProject
@ -198,6 +198,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestFramework.ForTestingMST
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HierarchyProject", "test\E2ETests\TestAssets\HierarchyProject\HierarchyProject.csproj", "{94A4DAA8-9645-4161-91F6-11EB1AD70EFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicDataTestProject", "test\E2ETests\TestAssets\DynamicDataTestProject\DynamicDataTestProject.csproj", "{B90E0931-2E90-4CE9-B107-ECD8E40C6B6C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -344,6 +346,10 @@ Global
{94A4DAA8-9645-4161-91F6-11EB1AD70EFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94A4DAA8-9645-4161-91F6-11EB1AD70EFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94A4DAA8-9645-4161-91F6-11EB1AD70EFC}.Release|Any CPU.Build.0 = Release|Any CPU
{B90E0931-2E90-4CE9-B107-ECD8E40C6B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B90E0931-2E90-4CE9-B107-ECD8E40C6B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B90E0931-2E90-4CE9-B107-ECD8E40C6B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B90E0931-2E90-4CE9-B107-ECD8E40C6B6C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -403,6 +409,7 @@ Global
{66608D86-416A-49AF-A937-C47F7E4586AE} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{0685FBC3-C3A9-43A9-B15C-15BAA39705FE} = {33D3029D-E653-4929-BB31-C714178C4BEE}
{94A4DAA8-9645-4161-91F6-11EB1AD70EFC} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{B90E0931-2E90-4CE9-B107-ECD8E40C6B6C} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31E0F4D5-975A-41CC-933E-545B2201FAF9}

Просмотреть файл

@ -1,169 +0,0 @@
// 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.IO;
using Microsoft.MSTestV2.CLIAutomation;
namespace Microsoft.MSTestV2.Smoke.DiscoveryAndExecutionTests;
public class DataRowTests : CLITestBase
{
private const string TestAssembly = "DataRowTestProject.dll";
public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerviedClassHasDataRows_SimpleDataRows()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "TestCategory~DataRowSimple");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethod (BaseString1)",
"DataRowTestMethod (BaseString2)",
"DataRowTestMethod (BaseString3)",
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
}
public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_SimpleDataRows()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DerivedClass&TestCategory~DataRowSimple");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
}
public void DataRowsExecuteWithRequiredAndOptionalParameters()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "TestCategory~DataRowSomeOptional");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethodWithSomeOptionalParameters (123)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString1)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString2,DerivedOptionalString3)");
}
public void DataRowsExecuteWithParamsArrayParameter()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "TestCategory~DataRowParamsArgument");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethodWithParamsParameters (2)",
"DataRowTestMethodWithParamsParameters (2,DerivedSingleParamsArg)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2,DerivedParamsArg3)");
}
public void DataRowsFailWhenInvalidArgumentsProvided()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "TestCategory~DataRowOptionalInvalidArguments");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
}
public void DataRowsShouldSerializeDoublesProperly()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTestDouble");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestDouble (10.01,20.01)",
"DataRowTestDouble (10.02,20.02)");
}
public void DataRowsShouldSerializeMixedTypesProperly()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTestMixed");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMixed (10,10,10,10,10,10,10,10)");
}
public void DataRowsShouldSerializeEnumsProperly()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowEnums");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowEnums ()",
"DataRowEnums (Alfa)",
"DataRowEnums (Beta)",
"DataRowEnums (Gamma)");
}
public void DataRowsShouldHandleNonSerializableValues()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowNonSerializable");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsDiscovered(
testCases,
"DataRowNonSerializable");
VerifyE2E.TestsPassed(
testResults,
"DataRowNonSerializable (System.String)",
"DataRowNonSerializable (System.Int32)",
"DataRowNonSerializable (DataRowTestProject.DerivedClass)");
}
}

Просмотреть файл

@ -6,7 +6,7 @@ using System.IO;
using Microsoft.MSTestV2.CLIAutomation;
namespace Microsoft.MSTestV2.Smoke.DiscoveryAndExecutionTests;
public class TestDataSourceExtensibilityTests : CLITestBase
public class DataExtensibilityTests : CLITestBase
{
private const string TestAssembly = "FxExtensibilityTestProject.dll";

Просмотреть файл

@ -6,25 +6,165 @@ using System.IO;
using Microsoft.MSTestV2.CLIAutomation;
namespace Microsoft.MSTestV2.Smoke.DiscoveryAndExecutionTests;
public class TestDataSourceTests : CLITestBase
public class DataRowTests : CLITestBase
{
private const string TestAssembly = "DataSourceTestProject.dll";
private const string TestAssembly = "DataRowTestProject.dll";
public void ExecuteDynamicDataTests()
public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerivedClassHasDataRows_SimpleDataRows()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "DynamicDataTest");
var testCases = DiscoverTests(assemblyPath, "TestCategory~DataRowSimple");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.ContainsTestsPassed(
VerifyE2E.TestsPassed(
testResults,
"DynamicDataTest (John;Doe,DataSourceTestProject.ITestDataSourceTests.User)");
"DataRowTestMethod (BaseString1)",
"DataRowTestMethod (BaseString2)",
"DataRowTestMethod (BaseString3)",
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
}
VerifyE2E.FailedTestCount(testResults, 0);
public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_SimpleDataRows()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DerivedClass&TestCategory~DataRowSimple");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
}
public void DataRowsExecuteWithRequiredAndOptionalParameters()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "TestCategory~DataRowSomeOptional");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethodWithSomeOptionalParameters (123)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString1)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString2,DerivedOptionalString3)");
}
public void DataRowsExecuteWithParamsArrayParameter()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "TestCategory~DataRowParamsArgument");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethodWithParamsParameters (2)",
"DataRowTestMethodWithParamsParameters (2,DerivedSingleParamsArg)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2,DerivedParamsArg3)");
}
public void DataRowsFailWhenInvalidArgumentsProvided()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTests_Regular&TestCategory~DataRowOptionalInvalidArguments");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
}
public void DataRowsShouldSerializeDoublesProperly()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTests_Regular.DataRowTestDouble");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestDouble (10.01,20.01)",
"DataRowTestDouble (10.02,20.02)");
}
public void DataRowsShouldSerializeMixedTypesProperly()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTests_DerivedClass.DataRowTestMixed");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMixed (10,10,10,10,10,10,10,10)");
}
public void DataRowsShouldSerializeEnumsProperly()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTests_DerivedClass.DataRowEnums");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowEnums ()",
"DataRowEnums (Alfa)",
"DataRowEnums (Beta)",
"DataRowEnums (Gamma)");
}
public void DataRowsShouldHandleNonSerializableValues()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTests_DerivedClass.DataRowNonSerializable");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.TestsDiscovered(
testCases,
"DataRowNonSerializable");
VerifyE2E.TestsPassed(
testResults,
"DataRowNonSerializable (System.String)",
"DataRowNonSerializable (System.Int32)",
"DataRowNonSerializable (DataRowTestProject.DataRowTests_DerivedClass)");
}
public void ExecuteDataRowTests_Enums()
@ -116,17 +256,17 @@ public class TestDataSourceTests : CLITestBase
testResults,
"DataRowNonSerializable (System.String)",
"DataRowNonSerializable (System.Int32)",
"DataRowNonSerializable (DataSourceTestProject.ITestDataSourceTests.DataRowTests_Enums)");
"DataRowNonSerializable (DataRowTestProject.DataRowTests_Enums)");
VerifyE2E.FailedTestCount(testResults, 0);
}
public void ExecuteRegular_DataRowTests()
public void ExecuteDataRowTests_Regular()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~Regular_DataRowTests");
var testCases = DiscoverTests(assemblyPath, "FullyQualifiedName~DataRowTests_Regular");
var testResults = RunTests(assemblyPath, testCases);
// Assert
@ -154,26 +294,4 @@ public class TestDataSourceTests : CLITestBase
VerifyE2E.FailedTestCount(testResults, 0);
}
// TODO @haplois | @evangelink: This test fails under CI - will be fixed in a future PR (Marked as private to ignore the test)
private void ExecuteCsvTestDataSourceTests()
{
// Arrange
var assemblyPath = Path.IsPathRooted(TestAssembly) ? TestAssembly : GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "CsvTestMethod");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.ContainsTestsPassed(
testResults,
"CsvTestMethod (Data Row 0)",
"CsvTestMethod (Data Row 2)");
VerifyE2E.ContainsTestsFailed(
testResults,
"CsvTestMethod (Data Row 1)",
"CsvTestMethod (Data Row 3)");
}
}

Просмотреть файл

@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.MSTestV2.CLIAutomation;
namespace Microsoft.MSTestV2.Smoke.DiscoveryAndExecutionTests;
public class DynamicDataTests : CLITestBase
{
private const string TestAssembly = "DynamicDataTestProject.dll";
public void ExecuteDynamicDataTests()
{
// Arrange
var assemblyPath = GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath);
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.ContainsTestsPassed(
testResults,
"DynamicDataTest_SourceMethod (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourceMethod (Jane;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourceProperty (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourceProperty (Jane;Doe,LibProjectReferencedByDataSourceTest.User)",
"Custom DynamicDataTestMethod DynamicDataTest_SourceMethod_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourceMethod_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourceProperty_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourceProperty_CustomDisplayName with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceMethod_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceMethod_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceProperty_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceProperty_CustomDisplayNameOtherType with 2 parameters",
"DynamicDataTest_SourceMethodOtherType (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourceMethodOtherType (Jane;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourcePropertyOtherType (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourcePropertyOtherType (Jane;Doe,LibProjectReferencedByDataSourceTest.User)",
"Custom DynamicDataTestMethod DynamicDataTest_SourceMethodOtherType_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourceMethodOtherType_CustomDisplayName with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceMethodOtherType_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceMethodOtherType_CustomDisplayNameOtherType with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourcePropertyOtherType_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourcePropertyOtherType_CustomDisplayName with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourcePropertyOtherType_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourcePropertyOtherType_CustomDisplayNameOtherType with 2 parameters",
"DynamicDataTestWithTestCategory (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTestWithTestCategory (Jane;Doe,LibProjectReferencedByDataSourceTest.User)");
VerifyE2E.FailedTestCount(testResults, 0);
}
public void ExecuteDynamicDataTestsWithCategoryFilter()
{
// Arrange
var assemblyPath = GetAssetFullPath(TestAssembly);
// Act
var testCases = DiscoverTests(assemblyPath, "TestCategory~DynamicDataWithCategory");
var testResults = RunTests(assemblyPath, testCases);
// Assert
VerifyE2E.ContainsTestsPassed(
testResults,
"DynamicDataTestWithTestCategory (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTestWithTestCategory (Jane;Doe,LibProjectReferencedByDataSourceTest.User)");
VerifyE2E.FailedTestCount(testResults, 0);
}
}

Просмотреть файл

@ -1,93 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.MSTestV2.CLIAutomation;
namespace MSTestAdapter.Smoke.E2ETests;
public class DataRowTests : CLITestBase
{
private const string TestAssembly = "DataRowTestProject.dll";
public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerviedClassHasDataRows_SimpleDataRows()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowSimple");
ValidatePassedTestsContain(
"DataRowTestMethod (BaseString1)",
"DataRowTestMethod (BaseString2)",
"DataRowTestMethod (BaseString3)",
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
// 3 tests of BaseClass.DataRowTestMethod - 3 data row results and no parent result
// 2 tests of DerivedClass.DataRowTestMethod - 2 data row results and no parent result
// Total 5 tests - Making sure that DerivedClass doesn't run BaseClass tests
ValidatePassedTestsCount(5);
}
public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_SimpleDataRows()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "FullyQualifiedName~DerivedClass&TestCategory~DataRowSimple");
ValidatePassedTestsContain(
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
// 2 tests of DerivedClass.DataRowTestMethod - 2 datarow result and no parent result
ValidatePassedTestsCount(2);
}
public void DataRowsExecuteWithRequiredAndOptionalParameters()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowSomeOptional");
ValidatePassedTestsContain(
"DataRowTestMethodWithSomeOptionalParameters (123)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString1)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString2,DerivedOptionalString3)");
// 3 tests of DerivedClass.DataRowTestMethodWithSomeOptionalParameters - 3 datarow result and no parent result
ValidatePassedTestsCount(3);
}
public void DataRowsExecuteWithAllOptionalParameters()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowAllOptional");
ValidatePassedTestsContain(
"DataRowTestMethodWithAllOptionalParameters ()",
"DataRowTestMethodWithAllOptionalParameters (123)",
"DataRowTestMethodWithAllOptionalParameters (123,DerivedOptionalString4)",
"DataRowTestMethodWithAllOptionalParameters (123,DerivedOptionalString5,DerivedOptionalString6)");
// 4 tests of DerivedClass.DataRowTestMethodWithAllOptionalParameters - 4 datarow result and no parent result
ValidatePassedTestsCount(4);
}
public void DataRowsExecuteWithParamsArrayParameter()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowParamsArgument");
ValidatePassedTestsContain(
"DataRowTestMethodWithParamsParameters (2)",
"DataRowTestMethodWithParamsParameters (2,DerivedSingleParamsArg)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2,DerivedParamsArg3)");
// 4 tests of DerivedClass.DataRowTestMethodWithParamsParameters - 4 datarow result and no parent result
ValidatePassedTestsCount(4);
}
public void DataRowsFailWhenInvalidArgumentsProvided()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowOptionalInvalidArguments");
ValidatePassedTestsContain(
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
// 3 tests of DerivedClass.DataRowTestMethodFailsWithInvalidArguments - 3 datarow result and no parent result
ValidatePassedTestsCount(3);
}
}

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.MSTestV2.CLIAutomation;
namespace MSTestAdapter.Smoke.E2ETests;
public class DynamicDataExtensibilityTests : CLITestBase
{
private const string TestAssembly = "FxExtensibilityTestProject.dll";
public void ExecuteDynamicDataExtensibilityTests()
{
InvokeVsTestForExecution(new string[] { TestAssembly });
ValidatePassedTestsContain(
"DynamicDataTestMethod1 (string,2,True)",
"DynamicDataTestMethod2 (string,4,True)",
"DynamicDataTestMethod3 (string,2,True)",
"DynamicDataTestMethod3 (string,4,True)");
ValidatePassedTestsContain(
"DynamicDataTestMethod4 (string,2,True)",
"DynamicDataTestMethod5 (string,4,True)",
"DynamicDataTestMethod6 (string,2,True)",
"DynamicDataTestMethod6 (string,4,True)");
}
}

Просмотреть файл

@ -4,10 +4,32 @@
using Microsoft.MSTestV2.CLIAutomation;
namespace MSTestAdapter.Smoke.E2ETests;
public class CustomTestExecutionExtensibilityTests : CLITestBase
public class DataExtensibilityTests : CLITestBase
{
private const string TestAssembly = "FxExtensibilityTestProject.dll";
public void ExecuteTestDataSourceExtensibilityTests()
{
InvokeVsTestForExecution(new string[] { TestAssembly });
ValidatePassedTestsContain("CustomTestDataSourceTestMethod1 (1,2,3)", "CustomTestDataSourceTestMethod1 (4,5,6)");
}
public void ExecuteDynamicDataExtensibilityTests()
{
InvokeVsTestForExecution(new string[] { TestAssembly });
ValidatePassedTestsContain(
"DynamicDataTestMethod1 (string,2,True)",
"DynamicDataTestMethod2 (string,4,True)",
"DynamicDataTestMethod3 (string,2,True)",
"DynamicDataTestMethod3 (string,4,True)");
ValidatePassedTestsContain(
"DynamicDataTestMethod4 (string,2,True)",
"DynamicDataTestMethod5 (string,4,True)",
"DynamicDataTestMethod6 (string,2,True)",
"DynamicDataTestMethod6 (string,4,True)");
}
public void ExecuteCustomTestExtensibilityTests()
{
InvokeVsTestForExecution(new string[] { TestAssembly });

Просмотреть файл

@ -4,22 +4,91 @@
using Microsoft.MSTestV2.CLIAutomation;
namespace MSTestAdapter.Smoke.E2ETests;
public class TestDataSourceTests : CLITestBase
public class DataRowTests : CLITestBase
{
private const string TestAssembly = "DataSourceTestProject.dll";
private const string TestAssembly = "DataRowTestProject.dll";
public void ExecuteDynamicDataTests()
public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerivedClassHasDataRows_SimpleDataRows()
{
// Arrange & Act
InvokeVsTestForExecution(
new string[] { TestAssembly },
testCaseFilter: "DynamicDataTest");
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowSimple");
// Assert
ValidatePassedTests(
"DynamicDataTest (John;Doe,DataSourceTestProject.ITestDataSourceTests.User)");
ValidatePassedTestsContain(
"DataRowTestMethod (BaseString1)",
"DataRowTestMethod (BaseString2)",
"DataRowTestMethod (BaseString3)",
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
ValidateFailedTestsCount(0);
// 3 tests of BaseClass.DataRowTestMethod - 3 data row results and no parent result
// 2 tests of DerivedClass.DataRowTestMethod - 2 data row results and no parent result
// Total 5 tests - Making sure that DerivedClass doesn't run BaseClass tests
ValidatePassedTestsCount(5);
}
public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_SimpleDataRows()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "FullyQualifiedName~DerivedClass&TestCategory~DataRowSimple");
ValidatePassedTestsContain(
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
// 2 tests of DerivedClass.DataRowTestMethod - 2 datarow result and no parent result
ValidatePassedTestsCount(2);
}
public void DataRowsExecuteWithRequiredAndOptionalParameters()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowSomeOptional");
ValidatePassedTestsContain(
"DataRowTestMethodWithSomeOptionalParameters (123)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString1)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString2,DerivedOptionalString3)");
// 3 tests of DerivedClass.DataRowTestMethodWithSomeOptionalParameters - 3 datarow result and no parent result
ValidatePassedTestsCount(3);
}
public void DataRowsExecuteWithAllOptionalParameters()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowAllOptional");
ValidatePassedTestsContain(
"DataRowTestMethodWithAllOptionalParameters ()",
"DataRowTestMethodWithAllOptionalParameters (123)",
"DataRowTestMethodWithAllOptionalParameters (123,DerivedOptionalString4)",
"DataRowTestMethodWithAllOptionalParameters (123,DerivedOptionalString5,DerivedOptionalString6)");
// 4 tests of DerivedClass.DataRowTestMethodWithAllOptionalParameters - 4 datarow result and no parent result
ValidatePassedTestsCount(4);
}
public void DataRowsExecuteWithParamsArrayParameter()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "TestCategory~DataRowParamsArgument");
ValidatePassedTestsContain(
"DataRowTestMethodWithParamsParameters (2)",
"DataRowTestMethodWithParamsParameters (2,DerivedSingleParamsArg)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2,DerivedParamsArg3)");
// 4 tests of DerivedClass.DataRowTestMethodWithParamsParameters - 4 datarow result and no parent result
ValidatePassedTestsCount(4);
}
public void DataRowsFailWhenInvalidArgumentsProvided()
{
InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "FullyQualifiedName~DataRowTests_Regular&TestCategory~DataRowOptionalInvalidArguments");
ValidatePassedTestsContain(
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
// 3 tests of DerivedClass.DataRowTestMethodFailsWithInvalidArguments - 3 datarow result and no parent result
ValidatePassedTestsCount(3);
}
public void ExecuteDataRowTests_Enums()
@ -105,7 +174,7 @@ public class TestDataSourceTests : CLITestBase
ValidatePassedTests(
"DataRowNonSerializable (System.String)",
"DataRowNonSerializable (System.Int32)",
"DataRowNonSerializable (DataSourceTestProject.ITestDataSourceTests.DataRowTests_Enums)");
"DataRowNonSerializable (DataRowTestProject.DataRowTests_Enums)");
ValidateFailedTestsCount(0);
}
@ -115,7 +184,7 @@ public class TestDataSourceTests : CLITestBase
// Arrange & Act
InvokeVsTestForExecution(
new string[] { TestAssembly },
testCaseFilter: "FullyQualifiedName~Regular_DataRowTests");
testCaseFilter: "FullyQualifiedName~DataRowTests_Regular");
// Assert
ValidatePassedTests(
@ -141,23 +210,4 @@ public class TestDataSourceTests : CLITestBase
ValidateFailedTestsCount(0);
}
// TODO @haplois | @evangelink: This test fails under CI - will be fixed in a future PR (marked as private to ignore the test)
private void ExecuteCsvTestDataSourceTests()
{
// Arrange & Act
InvokeVsTestForExecution(
new string[] { TestAssembly },
testCaseFilter: "CsvTestMethod");
// Assert
ValidatePassedTests(
"CsvTestMethod (Data Row 0)",
"CsvTestMethod (Data Row 2)");
ValidateFailedTests(
TestAssembly,
"CsvTestMethod (Data Row 1)",
"CsvTestMethod (Data Row 3)");
}
}

Просмотреть файл

@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.MSTestV2.CLIAutomation;
namespace MSTestAdapter.Smoke.E2ETests;
public class DataSourceTests : CLITestBase
{
private const string TestAssembly = "DataSourceTestProject.dll";
// TODO @haplois | @evangelink: This test fails under CI - will be fixed in a future PR (marked as private to ignore the test)
private void ExecuteCsvTestDataSourceTests()
{
// Arrange & Act
InvokeVsTestForExecution(
new string[] { TestAssembly },
testCaseFilter: "CsvTestMethod");
// Assert
ValidatePassedTests(
"CsvTestMethod (Data Row 0)",
"CsvTestMethod (Data Row 2)");
ValidateFailedTests(
TestAssembly,
"CsvTestMethod (Data Row 1)",
"CsvTestMethod (Data Row 3)");
}
}

Просмотреть файл

@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.MSTestV2.CLIAutomation;
namespace MSTestAdapter.Smoke.E2ETests;
public class DynamicDataTests : CLITestBase
{
private const string TestAssembly = "DynamicDataTestProject.dll";
public void ExecuteDynamicDataTests()
{
// Arrange & Act
InvokeVsTestForExecution(
new string[] { TestAssembly },
testCaseFilter: "DynamicDataTest");
// Assert
ValidatePassedTests(
"DynamicDataTest_SourceMethod (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourceMethod (Jane;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourceProperty (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourceProperty (Jane;Doe,LibProjectReferencedByDataSourceTest.User)",
"Custom DynamicDataTestMethod DynamicDataTest_SourceMethod_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourceMethod_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourceProperty_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourceProperty_CustomDisplayName with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceMethod_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceMethod_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceProperty_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceProperty_CustomDisplayNameOtherType with 2 parameters",
"DynamicDataTest_SourceMethodOtherType (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourceMethodOtherType (Jane;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourcePropertyOtherType (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTest_SourcePropertyOtherType (Jane;Doe,LibProjectReferencedByDataSourceTest.User)",
"Custom DynamicDataTestMethod DynamicDataTest_SourceMethodOtherType_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourceMethodOtherType_CustomDisplayName with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceMethodOtherType_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourceMethodOtherType_CustomDisplayNameOtherType with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourcePropertyOtherType_CustomDisplayName with 2 parameters",
"Custom DynamicDataTestMethod DynamicDataTest_SourcePropertyOtherType_CustomDisplayName with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourcePropertyOtherType_CustomDisplayNameOtherType with 2 parameters",
"UserDynamicDataTestMethod DynamicDataTest_SourcePropertyOtherType_CustomDisplayNameOtherType with 2 parameters",
"DynamicDataTestWithTestCategory (John;Doe,LibProjectReferencedByDataSourceTest.User)",
"DynamicDataTestWithTestCategory (Jane;Doe,LibProjectReferencedByDataSourceTest.User)");
ValidateFailedTestsCount(0);
}
}

Просмотреть файл

@ -1,16 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.MSTestV2.CLIAutomation;
namespace MSTestAdapter.Smoke.E2ETests;
public class TestDataSourceExtensibilityTests : CLITestBase
{
private const string TestAssembly = "FxExtensibilityTestProject.dll";
public void ExecuteTestDataSourceExtensibilityTests()
{
InvokeVsTestForExecution(new string[] { TestAssembly });
ValidatePassedTestsContain("CustomTestDataSourceTestMethod1 (1,2,3)", "CustomTestDataSourceTestMethod1 (4,5,6)");
}
}

Просмотреть файл

@ -1,4 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<IsPackable>false</IsPackable>
@ -10,8 +11,4 @@
<ProjectReference Include="$(RepoRoot)src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DataRowTestProject;
[TestClass]
public class BaseClass
public class DataRowTests_BaseClass
{
[TestCategory("DataRowSimple")]
[TestMethod]

Просмотреть файл

@ -1,14 +1,14 @@
// 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;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DataRowTestProject;
[TestClass]
public class DerivedClass : BaseClass
public class DataRowTests_DerivedClass : DataRowTests_BaseClass
{
[TestCategory("DataRowSimple")]
[TestMethod]
@ -99,7 +99,7 @@ public class DerivedClass : BaseClass
[TestMethod]
[DataRow(typeof(string))]
[DataRow(typeof(int))]
[DataRow(typeof(DerivedClass))]
[DataRow(typeof(DataRowTests_DerivedClass))]
public void DataRowNonSerializable(Type type)
{
Assert.IsTrue(true);

Просмотреть файл

@ -1,12 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace DataRowTestProject;
namespace DataSourceTestProject.ITestDataSourceTests;
[TestClass]
public class DataRowTests_Enums
{

Просмотреть файл

@ -1,12 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace DataSourceTestProject.ITestDataSourceTests;
namespace DataRowTestProject;
[TestClass]
public class DataRowTests_NonSerializablePaths
{

Просмотреть файл

@ -1,14 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace DataRowTestProject;
namespace DataSourceTestProject.ITestDataSourceTests;
[TestClass]
public class Regular_DataRowTests
public class DataRowTests_Regular
{
[TestMethod]
[DataRow(10)]

Просмотреть файл

@ -8,7 +8,6 @@
<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj" />
<ProjectReference Include="..\ReferencedProjectFromDataSourceTest\ReferencedProjectFromDataSourceTest.csproj" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -1,20 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace DataSourceTestProject;
namespace DataSourceTestProject.ITestDataSourceTests;
[TestClass]
public class DataRowTests_Regular
public class DataSourceTests
{
public TestContext TestContext
{
get;
set;
}
public TestContext TestContext { get; set; }
[TestMethod, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\a.csv", "a#csv", DataAccessMethod.Sequential)]
public void CsvTestMethod()

Просмотреть файл

@ -1,41 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
namespace DataSourceTestProject.ITestDataSourceTests;
[TestClass]
public class DynamicDataTests
{
[DataTestMethod()]
[DynamicData(nameof(GetParseUserDatas), DynamicDataSourceType.Method)]
public void DynamicDataTest(string userDatas, User expectedUser)
{
// Prepare
var srv = new UserService();
// Act
var user = srv.ParseUserDatas(userDatas);
// Assert
Assert.AreNotSame(user, expectedUser);
Assert.AreEqual(user.FirstName, expectedUser.FirstName);
Assert.AreEqual(user.LastName, expectedUser.LastName);
}
public static IEnumerable<object[]> GetParseUserDatas()
{
yield return new object[] {
"John;Doe",
new User()
{
FirstName = "John",
LastName = "Doe"
}
};
}
}

Просмотреть файл

@ -0,0 +1,66 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using LibProjectReferencedByDataSourceTest;
using System.Collections.Generic;
using System.Reflection;
namespace DynamicDataTestProject;
public class DataProvider
{
public static IEnumerable<object[]> GetUserDataAndExceptedParsedUser()
{
yield return new object[]
{
"John;Doe",
new User()
{
FirstName = "John",
LastName = "Doe"
}
};
yield return new object[]
{
"Jane;Doe",
new User()
{
FirstName = "Jane",
LastName = "Doe"
}
};
}
public static IEnumerable<object[]> UserDataAndExceptedParsedUser
{
get
{
yield return new object[]
{
"John;Doe",
new User()
{
FirstName = "John",
LastName = "Doe"
}
};
yield return new object[]
{
"Jane;Doe",
new User()
{
FirstName = "Jane",
LastName = "Doe"
}
};
}
}
public static string GetUserDynamicDataDisplayName(MethodInfo methodInfo, object[] data)
{
return string.Format("UserDynamicDataTestMethod {0} with {1} parameters", methodInfo.Name, data.Length);
}
}

Просмотреть файл

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>$(RepoRoot)artifacts\TestAssets\</OutputPath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj" />
<ProjectReference Include="..\LibProjectReferencedByDataSourceTest\LibProjectReferencedByDataSourceTest.csproj" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,185 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using LibProjectReferencedByDataSourceTest;
using DynamicDataTestProject;
using System.Reflection;
namespace DataSourceTestProject;
[TestClass]
public class DynamicDataTests
{
[DataTestMethod]
[DynamicData(nameof(GetParseUserData), DynamicDataSourceType.Method)]
public void DynamicDataTest_SourceMethod(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(ParseUserData), DynamicDataSourceType.Property)]
public void DynamicDataTest_SourceProperty(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(GetParseUserData), DynamicDataSourceType.Method,
DynamicDataDisplayName = nameof(GetCustomDynamicDataDisplayName))]
public void DynamicDataTest_SourceMethod_CustomDisplayName(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(ParseUserData), DynamicDataSourceType.Property,
DynamicDataDisplayName = nameof(GetCustomDynamicDataDisplayName))]
public void DynamicDataTest_SourceProperty_CustomDisplayName(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(GetParseUserData), DynamicDataSourceType.Method,
DynamicDataDisplayName = nameof(DataProvider.GetUserDynamicDataDisplayName), DynamicDataDisplayNameDeclaringType = typeof(DataProvider))]
public void DynamicDataTest_SourceMethod_CustomDisplayNameOtherType(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser); // todo
}
[DataTestMethod]
[DynamicData(nameof(ParseUserData), DynamicDataSourceType.Property,
DynamicDataDisplayName = nameof(DataProvider.GetUserDynamicDataDisplayName), DynamicDataDisplayNameDeclaringType = typeof(DataProvider))]
public void DynamicDataTest_SourceProperty_CustomDisplayNameOtherType(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser); // todo
}
[DataTestMethod]
[DynamicData(nameof(DataProvider.GetUserDataAndExceptedParsedUser), typeof(DataProvider), DynamicDataSourceType.Method)]
public void DynamicDataTest_SourceMethodOtherType(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(DataProvider.UserDataAndExceptedParsedUser), typeof(DataProvider), DynamicDataSourceType.Property)]
public void DynamicDataTest_SourcePropertyOtherType(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(DataProvider.GetUserDataAndExceptedParsedUser), typeof(DataProvider), DynamicDataSourceType.Method,
DynamicDataDisplayName = nameof(GetCustomDynamicDataDisplayName))]
public void DynamicDataTest_SourceMethodOtherType_CustomDisplayName(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(DataProvider.UserDataAndExceptedParsedUser), typeof(DataProvider), DynamicDataSourceType.Property,
DynamicDataDisplayName = nameof(GetCustomDynamicDataDisplayName))]
public void DynamicDataTest_SourcePropertyOtherType_CustomDisplayName(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(DataProvider.GetUserDataAndExceptedParsedUser), typeof(DataProvider), DynamicDataSourceType.Method,
DynamicDataDisplayName = nameof(DataProvider.GetUserDynamicDataDisplayName), DynamicDataDisplayNameDeclaringType = typeof(DataProvider))]
public void DynamicDataTest_SourceMethodOtherType_CustomDisplayNameOtherType(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[DataTestMethod]
[DynamicData(nameof(DataProvider.UserDataAndExceptedParsedUser), typeof(DataProvider), DynamicDataSourceType.Property,
DynamicDataDisplayName = nameof(DataProvider.GetUserDynamicDataDisplayName), DynamicDataDisplayNameDeclaringType = typeof(DataProvider))]
public void DynamicDataTest_SourcePropertyOtherType_CustomDisplayNameOtherType(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
[TestCategory("DynamicDataWithCategory")]
[DataTestMethod]
[DynamicData(nameof(GetParseUserData), DynamicDataSourceType.Method)]
public void DynamicDataTestWithTestCategory(string userData, User expectedUser)
{
ParseAndAssert(userData, expectedUser);
}
private static void ParseAndAssert(string userData, User expectedUser)
{
// Prepare
var service = new UserService();
// Act
var user = service.ParseUserData(userData);
// Assert
Assert.AreNotSame(user, expectedUser);
Assert.AreEqual(user.FirstName, expectedUser.FirstName);
Assert.AreEqual(user.LastName, expectedUser.LastName);
}
public static IEnumerable<object[]> GetParseUserData()
{
yield return new object[]
{
"John;Doe",
new User()
{
FirstName = "John",
LastName = "Doe"
}
};
yield return new object[]
{
"Jane;Doe",
new User()
{
FirstName = "Jane",
LastName = "Doe"
}
};
}
public static IEnumerable<object[]> ParseUserData
{
get
{
yield return new object[]
{
"John;Doe",
new User()
{
FirstName = "John",
LastName = "Doe"
}
};
yield return new object[]
{
"Jane;Doe",
new User()
{
FirstName = "Jane",
LastName = "Doe"
}
};
}
}
public static string GetCustomDynamicDataDisplayName(MethodInfo methodInfo, object[] data)
{
return string.Format("Custom DynamicDataTestMethod {0} with {1} parameters", methodInfo.Name, data.Length);
}
}

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace DataSourceTestProject.ITestDataSourceTests;
namespace LibProjectReferencedByDataSourceTest;
public class User
{
@ -12,14 +12,14 @@ public class User
public class UserService
{
public User ParseUserDatas(string datas)
public User ParseUserData(string data)
{
var splittedDatas = datas.Split(';');
var splittedData = data.Split(';');
return new User()
{
FirstName = splittedDatas[0],
LastName = splittedDatas[1]
FirstName = splittedData[0],
LastName = splittedData[1]
};
}
}