diff --git a/TestFx.sln b/TestFx.sln index 61f330377d..956ed1d772 100644 --- a/TestFx.sln +++ b/TestFx.sln @@ -178,6 +178,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompatTestProject", "test\E EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProjectForAssemblyResolution", "test\ComponentTests\TestAssets\TestProjectForAssemblyResolution\TestProjectForAssemblyResolution.csproj", "{0B057B99-DCDD-417A-BC19-3E63DDD86F24}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataRowTestProject", "test\E2ETests\TestAssets\DataRowTestProject\DataRowTestProject.csproj", "{7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution src\TestFramework\Extension.Shared\Extension.Shared.projitems*{272ca5e1-8e81-4825-9e47-86cce02f700d}*SharedItemsImports = 13 @@ -1039,6 +1041,30 @@ Global {0B057B99-DCDD-417A-BC19-3E63DDD86F24}.Release|x64.Build.0 = Release|Any CPU {0B057B99-DCDD-417A-BC19-3E63DDD86F24}.Release|x86.ActiveCfg = Release|Any CPU {0B057B99-DCDD-417A-BC19-3E63DDD86F24}.Release|x86.Build.0 = Release|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Code Analysis Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Code Analysis Debug|Any CPU.Build.0 = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Code Analysis Debug|ARM.ActiveCfg = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Code Analysis Debug|ARM.Build.0 = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Code Analysis Debug|x64.ActiveCfg = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Code Analysis Debug|x64.Build.0 = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Code Analysis Debug|x86.ActiveCfg = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Code Analysis Debug|x86.Build.0 = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Debug|ARM.ActiveCfg = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Debug|ARM.Build.0 = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Debug|x64.ActiveCfg = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Debug|x64.Build.0 = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Debug|x86.ActiveCfg = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Debug|x86.Build.0 = Debug|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Release|Any CPU.Build.0 = Release|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Release|ARM.ActiveCfg = Release|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Release|ARM.Build.0 = Release|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Release|x64.ActiveCfg = Release|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Release|x64.Build.0 = Release|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Release|x86.ActiveCfg = Release|Any CPU + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1098,6 +1124,7 @@ Global {3FCE3987-7C8C-4E12-B54A-C6EC2D9FC7A6} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8} {2D2C5B73-F1F1-47C8-BC5C-A172E9BB3D16} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8} {0B057B99-DCDD-417A-BC19-3E63DDD86F24} = {1899187D-8B9C-40C2-9F04-9E9A76C9A919} + {7FB80AAB-7123-4416-B6CD-8D3D69AA83F1} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {31E0F4D5-975A-41CC-933E-545B2201FAF9} diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs index 4ac11553a2..fc7b8b57ed 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs @@ -303,7 +303,7 @@ internal UnitTestResult[] RunTestMethod() } else { - UTF.ITestDataSource[] testDataSources = this.testMethodInfo.GetAttributes(true)?.Where(a => a is UTF.ITestDataSource).OfType().ToArray(); + UTF.ITestDataSource[] testDataSources = this.testMethodInfo.GetAttributes(false)?.Where(a => a is UTF.ITestDataSource).OfType().ToArray(); if (testDataSources != null && testDataSources.Length > 0) { diff --git a/test/E2ETests/Automation.CLI/CLITestBase.cs b/test/E2ETests/Automation.CLI/CLITestBase.cs index 2dc761445b..42b9cad4a9 100644 --- a/test/E2ETests/Automation.CLI/CLITestBase.cs +++ b/test/E2ETests/Automation.CLI/CLITestBase.cs @@ -117,12 +117,16 @@ public void ValidateDiscoveredTests(params string[] discoveredTestsList) /// Provide the full test name similar to this format SampleTest.TestCode.TestMethodPass. public void ValidatePassedTests(params string[] passedTests) { - // Make sure only expected number of tests passed and not more. - Assert.AreEqual(passedTests.Length, this.runEventsHandler.PassedTests.Count); - + this.ValidatePassedTestsCount(passedTests.Length); this.ValidatePassedTestsContain(passedTests); } + public void ValidatePassedTestsCount(int expectedPassedTestsCount) + { + // Make sure only expected number of tests passed and not more. + Assert.AreEqual(expectedPassedTestsCount, this.runEventsHandler.PassedTests.Count); + } + /// /// Validates if the test results have the specified set of failed tests. /// diff --git a/test/E2ETests/Smoke.E2E.Tests/DataRowTests.cs b/test/E2ETests/Smoke.E2E.Tests/DataRowTests.cs new file mode 100644 index 0000000000..6967befb57 --- /dev/null +++ b/test/E2ETests/Smoke.E2E.Tests/DataRowTests.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.Smoke.E2ETests +{ + using Microsoft.MSTestV2.CLIAutomation; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class DataRowTests : CLITestBase + { + private const string TestAssembly = "DataRowTestProject.dll"; + + [TestMethod] + public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerviedClassHasDataRows() + { + this.InvokeVsTestForExecution(new string[] { TestAssembly }); + + this.ValidatePassedTestsContain( + "DataRowTestMethod (BaseString1)", + "DataRowTestMethod (BaseString2)", + "DataRowTestMethod (BaseString3)", + "DataRowTestMethod (DerivedString1)", + "DataRowTestMethod (DerivedString2)"); + + // 4 tests of BaseClass - 3 datarow result and 1 parent result + // 3 tests of DerivedClass - 2 datarow result and 1 parent result + // Total 7 tests - Making sure that DerivedClass doesn't run BaseClass tests + this.ValidatePassedTestsCount(7); + } + + [TestMethod] + public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows() + { + this.InvokeVsTestForExecution(new string[] { TestAssembly }, testCaseFilter: "FullyQualifiedName~DerivedClass"); + + this.ValidatePassedTestsContain( + "DataRowTestMethod (DerivedString1)", + "DataRowTestMethod (DerivedString2)"); + + // 3 tests of DerivedClass - 2 datarow result and 1 parent result + this.ValidatePassedTestsCount(3); + } + } +} diff --git a/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj b/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj index 4078045120..ffc75ae641 100644 --- a/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj +++ b/test/E2ETests/Smoke.E2E.Tests/Smoke.E2E.Tests.csproj @@ -48,6 +48,7 @@ + diff --git a/test/E2ETests/TestAssets/DataRowTestProject/BaseClass.cs b/test/E2ETests/TestAssets/DataRowTestProject/BaseClass.cs new file mode 100644 index 0000000000..75183e05a5 --- /dev/null +++ b/test/E2ETests/TestAssets/DataRowTestProject/BaseClass.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace DataRowTestProject +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class BaseClass + { + [TestMethod] + [DataRow("BaseString1")] + [DataRow("BaseString2")] + [DataRow("BaseString3")] + public virtual void DataRowTestMethod(string a) + { + Assert.IsTrue(true); + } + } +} diff --git a/test/E2ETests/TestAssets/DataRowTestProject/DataRowTestProject.csproj b/test/E2ETests/TestAssets/DataRowTestProject/DataRowTestProject.csproj new file mode 100644 index 0000000000..56d97e8d71 --- /dev/null +++ b/test/E2ETests/TestAssets/DataRowTestProject/DataRowTestProject.csproj @@ -0,0 +1,23 @@ + + + + ..\..\..\..\ + + + + net452 + false + false + $(TestFxRoot)artifacts\TestAssets\ + + + + + + + + + + + + diff --git a/test/E2ETests/TestAssets/DataRowTestProject/DerivedClass.cs b/test/E2ETests/TestAssets/DataRowTestProject/DerivedClass.cs new file mode 100644 index 0000000000..0ecc6ecf05 --- /dev/null +++ b/test/E2ETests/TestAssets/DataRowTestProject/DerivedClass.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace DataRowTestProject +{ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class DerivedClass : BaseClass + { + [TestMethod] + [DataRow("DerivedString1")] + [DataRow("DerivedString2")] + public override void DataRowTestMethod(string a) + { + Assert.IsTrue(true); + } + } +}