diff --git a/TestFx.sln b/TestFx.sln index 204ffc536c..26301f9a0a 100644 --- a/TestFx.sln +++ b/TestFx.sln @@ -182,8 +182,11 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Analyzers.Package", "src\Analyzers\MSTest.Analyzers.Package\MSTest.Analyzers.Package.csproj", "{DC068986-7549-4B75-8EFC-A9958FD5CF88}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Analyzers.Test", "test\UnitTests\MSTest.Analyzers.Test\MSTest.Analyzers.Test.csproj", "{1FF35C23-C128-4C95-B3F8-67B1B4C51E4D}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Sdk", "src\Package\MSTest.Sdk\MSTest.Sdk.csproj", "{10930CFD-EDF9-4486-B0A3-49230B5A6798}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClsTestProject", "test\IntegrationTests\TestAssets\ClsTestProject\ClsTestProject.csproj", "{100CF515-8291-45FF-9FFD-2A9064FECC72}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -386,6 +389,10 @@ Global {10930CFD-EDF9-4486-B0A3-49230B5A6798}.Debug|Any CPU.Build.0 = Debug|Any CPU {10930CFD-EDF9-4486-B0A3-49230B5A6798}.Release|Any CPU.ActiveCfg = Release|Any CPU {10930CFD-EDF9-4486-B0A3-49230B5A6798}.Release|Any CPU.Build.0 = Release|Any CPU + {100CF515-8291-45FF-9FFD-2A9064FECC72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {100CF515-8291-45FF-9FFD-2A9064FECC72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {100CF515-8291-45FF-9FFD-2A9064FECC72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {100CF515-8291-45FF-9FFD-2A9064FECC72}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -455,6 +462,7 @@ Global {DC068986-7549-4B75-8EFC-A9958FD5CF88} = {E7F15C9C-3928-47AD-8462-64FD29FFCA54} {1FF35C23-C128-4C95-B3F8-67B1B4C51E4D} = {BB874DF1-44FE-415A-B634-A6B829107890} {10930CFD-EDF9-4486-B0A3-49230B5A6798} = {E374A3A6-C364-4890-B315-D60F5C682B6E} + {100CF515-8291-45FF-9FFD-2A9064FECC72} = {C9F82701-0E0F-4E61-B05B-AE387E7631F6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {31E0F4D5-975A-41CC-933E-545B2201FAF9} diff --git a/src/TestFramework/TestFramework/Attributes/DataSource/DataRowAttribute.cs b/src/TestFramework/TestFramework/Attributes/DataSource/DataRowAttribute.cs index e1f64b481e..a4c51a27ca 100644 --- a/src/TestFramework/TestFramework/Attributes/DataSource/DataRowAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/DataSource/DataRowAttribute.cs @@ -21,7 +21,17 @@ public DataRowAttribute() } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class with an array of object arguments. + /// + /// The data. + /// This constructor is only kept for CLS compliant tests. + public DataRowAttribute(object? data) + { + Data = data is not null ? [data] : [null]; + } + + /// + /// Initializes a new instance of the class with an array of string arguments. /// /// The string array data. public DataRowAttribute(string?[]? stringArrayData) @@ -30,7 +40,7 @@ public DataRowAttribute(string?[]? stringArrayData) } /// - /// Initializes a new instance of the class which takes in an array of arguments. + /// Initializes a new instance of the class with an array of object arguments. /// /// The data. public DataRowAttribute(params object?[]? data) diff --git a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt index ab058de62d..a4c539fdc2 100644 --- a/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt @@ -1 +1,2 @@ #nullable enable +Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute.DataRowAttribute(object? data) -> void diff --git a/test/IntegrationTests/MSTest.IntegrationTests/ClsTests.cs b/test/IntegrationTests/MSTest.IntegrationTests/ClsTests.cs new file mode 100644 index 0000000000..87f597f921 --- /dev/null +++ b/test/IntegrationTests/MSTest.IntegrationTests/ClsTests.cs @@ -0,0 +1,28 @@ +// 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 MSTest.IntegrationTests; + +public class ClsTests : CLITestBase +{ + private const string TestAssetName = "ClsTestProject"; + + public void TestsAreRun() + { + // Arrange + var assemblyPath = GetAssetFullPath(TestAssetName); + + // Act + var testCases = DiscoverTests(assemblyPath); + var testResults = RunTests(testCases); + + // Assert + VerifyE2E.TestsPassed( + testResults, + "TestMethod", + "IntDataRow (10)", + "StringDataRow (some string)"); + } +} diff --git a/test/IntegrationTests/TestAssets/ClsTestProject/ClsTestProject.csproj b/test/IntegrationTests/TestAssets/ClsTestProject/ClsTestProject.csproj new file mode 100644 index 0000000000..c272e52833 --- /dev/null +++ b/test/IntegrationTests/TestAssets/ClsTestProject/ClsTestProject.csproj @@ -0,0 +1,12 @@ + + + + net462 + false + + + + + + + diff --git a/test/IntegrationTests/TestAssets/ClsTestProject/MyTests.cs b/test/IntegrationTests/TestAssets/ClsTestProject/MyTests.cs new file mode 100644 index 0000000000..dfbf855de4 --- /dev/null +++ b/test/IntegrationTests/TestAssets/ClsTestProject/MyTests.cs @@ -0,0 +1,34 @@ +// 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; + +[assembly: CLSCompliant(true)] + +namespace DataRowTestProject; + +[TestClass] +public class ClsTests +{ + [TestMethod] + public void TestMethod() + { + Assert.IsTrue(true); + } + + [TestMethod] + [DataRow(10)] + public void IntDataRow(int i) + { + Assert.IsTrue(i != 0); + } + + [TestMethod] + [DataRow("some string")] + public void StringDataRow(string s) + { + Assert.IsNotNull(s); + } +}