You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/testing/unit-testing-fsharp-with-dotnet-test.md
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ Make *MathService* the current directory and run [`dotnet new classlib -lang F#`
32
32
33
33
```fsharp
34
34
module MyMath =
35
-
let sumOfSquares xs = raise (System.NotImplementedException("You haven't written a test yet!"))
35
+
let squaresOfOdds xs = raise (System.NotImplementedException("You haven't written a test yet!"))
36
36
```
37
37
38
38
Change the directory back to the *unit-testing-with-fsharp* directory. Run [`dotnet sln add .\MathService\MathService.fsproj`](../tools/dotnet-sln.md)
@@ -99,22 +99,22 @@ let ``Fail every time`` () = Assert.True(false)
99
99
100
100
The `[<Fact>]` attribute denotes a test method that is run by the test runner. From the *unit-testing-with-fsharp*, execute [`dotnet test`](../tools/dotnet-test.md) to build the tests and the class library and then run the tests. The xUnit test runner contains the program entry point to run your tests. `dotnet test` starts the test runner using the unit test project you've created.
101
101
102
-
These two tests show the most basic passing and failing tests. `My test` passes, and `Fail every time` fails. Now, create a test for the `sumOfSquares` method. The `sumOfSquares` method returns the sum of the squares of all odd integer values that are part of the input sequence. Rather than trying to write all of those functions at once, you can iteratively create tests that validate the functionality. Making each test pass means creating the necessary functionality for the method.
102
+
These two tests show the most basic passing and failing tests. `My test` passes, and `Fail every time` fails. Now, create a test for the `squaresOfOdds` method. The `squaresOfOdds` method returns a sequence of the squares of all odd integer values that are part of the input sequence. Rather than trying to write all of those functions at once, you can iteratively create tests that validate the functionality. Making each test pass means creating the necessary functionality for the method.
103
103
104
-
The simplest test we can write is to call `sumOfSquares` with all even numbers, where the result should be an empty sequence of integers. Here's that test:
104
+
The simplest test we can write is to call `squaresOfOdds` with all even numbers, where the result should be an empty sequence of integers. Here's that test:
105
105
106
106
```fsharp
107
107
[<Fact>]
108
-
let ``Sum of evens returns empty collection`` () =
108
+
let ``Sequence of Evens returns empty collection`` () =
109
109
let expected = Seq.empty<int>
110
-
let actual = MyMath.sumOfSquares [2; 4; 6; 8; 10]
110
+
let actual = MyMath.squaresOfOdds [2; 4; 6; 8; 10]
Copy file name to clipboardExpand all lines: docs/core/testing/unit-testing-fsharp-with-mstest.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ Make *MathService* the current directory and run [`dotnet new classlib -lang F#`
32
32
33
33
```fsharp
34
34
module MyMath =
35
-
let sumOfSquares xs = raise (System.NotImplementedException("You haven't written a test yet!"))
35
+
let squaresOfOdds xs = raise (System.NotImplementedException("You haven't written a test yet!"))
36
36
```
37
37
38
38
Change the directory back to the *unit-testing-with-fsharp* directory. Run [`dotnet sln add .\MathService\MathService.fsproj`](../tools/dotnet-sln.md)
@@ -108,15 +108,15 @@ type TestClass () =
108
108
109
109
The `[<TestClass>]` attribute denotes a class that contains tests. The `[<TestMethod>]` attribute denotes a test method that is run by the test runner. From the *unit-testing-with-fsharp* directory, execute [`dotnet test`](../tools/dotnet-test.md) to build the tests and the class library and then run the tests. The MSTest test runner contains the program entry point to run your tests. `dotnet test` starts the test runner using the unit test project you've created.
110
110
111
-
These two tests show the most basic passing and failing tests. `My test` passes, and `Fail every time` fails. Now, create a test for the `sumOfSquares` method. The `sumOfSquares` method returns the sum of the squares of all odd integer values that are part of the input sequence. Rather than trying to write all of those functions at once, you can iteratively create tests that validate the functionality. Making each test pass means creating the necessary functionality for the method.
111
+
These two tests show the most basic passing and failing tests. `My test` passes, and `Fail every time` fails. Now, create a test for the `squaresOfOdds` method. The `squaresOfOdds` method returns a list of the squares of all odd integer values that are part of the input sequence. Rather than trying to write all of those functions at once, you can iteratively create tests that validate the functionality. Making each test pass means creating the necessary functionality for the method.
112
112
113
-
The simplest test we can write is to call `sumOfSquares` with all even numbers, where the result should be an empty sequence of integers. Here's that test:
113
+
The simplest test we can write is to call `squaresOfOdds` with all even numbers, where the result should be an empty sequence of integers. Here's that test:
114
114
115
115
```fsharp
116
116
[<TestMethod>]
117
117
member this.TestEvenSequence() =
118
118
let expected = Seq.empty<int> |> Seq.toList
119
-
let actual = MyMath.sumOfSquares [2; 4; 6; 8; 10]
119
+
let actual = MyMath.squaresOfOdds [2; 4; 6; 8; 10]
120
120
Assert.AreEqual(expected, actual)
121
121
```
122
122
@@ -125,7 +125,7 @@ Notice that the `expected` sequence has been converted to a list. The MSTest lib
125
125
When you run the test, you see that your test fails. You haven't created the implementation yet. Make this test by writing the simplest code in the `Mathservice` class that works:
126
126
127
127
```csharp
128
-
letsumOfSquaresxs=
128
+
letsquaresOfOddsxs=
129
129
Seq.empty<int>|>Seq.toList
130
130
```
131
131
@@ -137,18 +137,18 @@ Now that you've made one test pass, it's time to write more. The next simple cas
Copy file name to clipboardExpand all lines: docs/core/testing/unit-testing-fsharp-with-nunit.md
+13-15Lines changed: 13 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Make *MathService* the current directory and run [`dotnet new classlib -lang F#`
29
29
30
30
```fsharp
31
31
module MyMath =
32
-
let sumOfSquares xs = raise (System.NotImplementedException("You haven't written a test yet!"))
32
+
let squaresOfOdds xs = raise (System.NotImplementedException("You haven't written a test yet!"))
33
33
```
34
34
35
35
Change the directory back to the *unit-testing-with-fsharp* directory. Run [`dotnet sln add .\MathService\MathService.fsproj`](../tools/dotnet-sln.md)
@@ -113,15 +113,15 @@ type TestClass () =
113
113
114
114
The `[<TestFixture>]` attribute denotes a class that contains tests. The `[<Test>]` attribute denotes a test method that is run by the test runner. From the *unit-testing-with-fsharp* directory, execute [`dotnet test`](../tools/dotnet-test.md) to build the tests and the class library and then run the tests. The NUnit test runner contains the program entry point to run your tests. `dotnet test` starts the test runner using the unit test project you've created.
115
115
116
-
These two tests show the most basic passing and failing tests. `My test` passes, and `Fail every time` fails. Now, create a test for the `sumOfSquares` method. The `sumOfSquares` method returns the sum of the squares of all odd integer values that are part of the input sequence. Rather than trying to write all of those functions at once, you can iteratively create tests that validate the functionality. Making each test pass means creating the necessary functionality for the method.
116
+
These two tests show the most basic passing and failing tests. `My test` passes, and `Fail every time` fails. Now, create a test for the `squaresOfOdds` method. The `squaresOfOdds` method returns a sequence of the squares of all odd integer values that are part of the input sequence. Rather than trying to write all of those functions at once, you can iteratively create tests that validate the functionality. Making each test pass means creating the necessary functionality for the method.
117
117
118
-
The simplest test we can write is to call `sumOfSquares` with all even numbers, where the result should be an empty sequence of integers. Here's that test:
118
+
The simplest test we can write is to call `squaresOfOdds` with all even numbers, where the result should be an empty sequence of integers. Here's that test:
119
119
120
120
```fsharp
121
121
[<Test>]
122
122
member this.TestEvenSequence() =
123
-
let expected = Seq.empty<int> |> Seq.toList
124
-
let actual = MyMath.sumOfSquares [2; 4; 6; 8; 10]
123
+
let expected = Seq.empty<int>
124
+
let actual = MyMath.squaresOfOdds [2; 4; 6; 8; 10]
125
125
Assert.That(actual, Is.EqualTo(expected))
126
126
```
127
127
@@ -130,8 +130,8 @@ Notice that the `expected` sequence has been converted to a list. The NUnit fram
130
130
When you run the test, you see that your test fails. You haven't created the implementation yet. Make this test by writing the simplest code in the `Mathservice` class that works:
131
131
132
132
```csharp
133
-
letsumOfSquaresxs=
134
-
Seq.empty<int>|>Seq.toList
133
+
letsquaresOfOddsxs=
134
+
Seq.empty<int>
135
135
```
136
136
137
137
Inthe*unit-testing-with-fsharp*directory, run `dotnettest` again. The `dotnettest` commandrunsabuildfor the `MathService` project and then for the `MathService.Tests` project. After building both projects, it runs this single test. It passes.
@@ -142,21 +142,20 @@ Now that you've made one test pass, it's time to write more. The next simple cas
@@ -177,11 +176,10 @@ You can fix the test by piping the filtered sequence through a map operation to
177
176
letprivatesquarex=x*x
178
177
letprivateisOddx=x%2<>0
179
178
180
-
letsumOfSquaresxs=
179
+
letsquaresOfOddsxs=
181
180
xs
182
181
|>Seq.filterisOdd
183
182
|>Seq.mapsquare
184
-
|>Seq.toList
185
183
```
186
184
187
185
You've built a small library and a set of unit tests for that library. You'vestructuredthesolutionsothataddingnewpackagesandtestsispartofthenormalworkflow. You'veconcentratedmostofyourtimeandeffortonsolvingthegoalsoftheapplication.
0 commit comments