Skip to content

Commit 1095be2

Browse files
authored
Switch DataTestMethod to TestMethod (#43783)
* Switch DataTestMethod to TestMethod * Update sample code * Update attributes doc as well
1 parent db88975 commit 1095be2

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

docs/core/testing/unit-testing-mstest-writing-tests-attributes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ Use the following elements to set up data-driven tests. For more information, se
6969

7070
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute>
7171
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute>
72-
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataTestMethodAttribute>
72+
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute>
7373
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute>
7474

7575
### `DataRowAttribute`
7676

77-
The `DataRowAttribute` allows you to run the same test method with multiple different inputs. It can appear one or multiple times on a test method. It should be combined with `TestMethodAttribute` or `DataTestMethodAttribute`.
77+
The `DataRowAttribute` allows you to run the same test method with multiple different inputs. It can appear one or multiple times on a test method. It should be combined with `TestMethodAttribute`.
7878

7979
The number and types of arguments must exactly match the test method signature. Consider the following example of a valid test class demonstrating the `DataRow` attribute usage with inline arguments that align to test method parameters:
8080

docs/core/testing/unit-testing-visual-basic-with-mstest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ In the *unit-testing-vb-mstest* directory, run `dotnet test` again. The `dotnet
124124

125125
## Adding more features
126126

127-
Now that you've made one test pass, it's time to write more. There are a few other simple cases for prime numbers: 0, -1. You could add those cases as new tests with the `<TestMethod>` attribute, but that quickly becomes tedious. There are other MSTest attributes that enable you to write a suite of similar tests. A `<DataTestMethod>` attribute represents a suite of tests that execute the same code but have different input arguments. You can use the `<DataRow>` attribute to specify values for those inputs.
127+
Now that you've made one test pass, it's time to write more. There are a few other simple cases for prime numbers: 0, -1. You could add those cases as new tests with the `<TestMethod>` attribute, but that quickly becomes tedious. There are other MSTest attributes that enable you to write a suite of similar tests. You can use the `<DataRow>` attribute along with `<TestMethod>` attribute to specify values for those inputs.
128128

129129
Instead of creating new tests, apply these two attributes to create a single theory. The theory is a method that tests several values less than two, which is the lowest prime number:
130130

samples/snippets/core/testing/unit-testing-vb-mstest/vb/PrimeService.Tests/PrimeService_IsPrimeShould.vb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Namespace PrimeService.Tests
66
Public Class PrimeService_IsPrimeShould
77
Private _primeService As Prime.Services.PrimeService = New Prime.Services.PrimeService()
88

9-
<DataTestMethod>
9+
<TestMethod>
1010
<DataRow(-1)>
1111
<DataRow(0)>
1212
<DataRow(1)>
@@ -16,7 +16,7 @@ Namespace PrimeService.Tests
1616
Assert.IsFalse(result, $"{value} should not be prime")
1717
End Sub
1818

19-
<DataTestMethod>
19+
<TestMethod>
2020
<DataRow(2)>
2121
<DataRow(3)>
2222
<DataRow(5)>
@@ -27,7 +27,7 @@ Namespace PrimeService.Tests
2727
Assert.IsTrue(result, $"{value} should be prime")
2828
End Sub
2929

30-
<DataTestMethod>
30+
<TestMethod>
3131
<DataRow(4)>
3232
<DataRow(6)>
3333
<DataRow(8)>

0 commit comments

Comments
 (0)