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
Thetestlooksfor an <xref:System.ArgumentOutOfRangeException> and if it catches one, the test passes. In this case, the expected exception wasn't thrown.
253
-
254
-
4. Add code to the beginning of the **SquareRoot** method to check the input and throw an exception if it is negative:
255
-
256
-
```csharp
257
-
public double SquareRoot(doublex)
258
-
{
259
-
if (x<0.0)
260
-
{
261
-
thrownewArgumentOutOfRangeException();
262
-
}
263
-
...
264
-
```
265
-
266
-
5. Runalloftheteststomakesurethatyouhaven't introduced a regression.
In this section, you refactor both app and test code, then rerun tests to make sure they still pass.
215
+
274
216
### Simplify the square root estimation
275
217
276
218
1. Simplify the central calculation in the **SquareRoot** function by changing one line of code, as follows:
@@ -290,9 +232,9 @@ You've set up the test and app projects and verified that you can run tests that
290
232
291
233
### Eliminate duplicated code
292
234
293
-
The**RangeTest**methodhardcodesthedenominatorofthe`tolerance`variablethat's passed to the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Assert> method. If you plan to add additional tests that use the same tolerance calculation, the use of a hard-coded value in multiple locations could lead to errors.
235
+
The**RangeTest**methodhardcodesthedenominatorofthe*tolerance*variablethat's passed to the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Assert> method. If you plan to add additional tests that use the same tolerance calculation, the use of a hard-coded value in multiple locations makes the code harder to maintain.
1. Addaprivatehelpermethodtothe**UnitTest1**classto calculate the tolerance value, and then call that method from **RangeTest**.
296
238
297
239
```csharp
298
240
private double ToleranceHelper(doubleexpected)
@@ -319,3 +261,7 @@ The **RangeTest** method hard codes the denominator of the `tolerance` variable
319
261
320
262
> [!TIP]
321
263
>Ifyouaddahelpermethodtoatest class, and you don't want it to appear in **Test Explorer**, don't add the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute> attribute to the method.
264
+
265
+
## See also
266
+
267
+
- [Walkthrough: Test-driven development using Test Explorer](quick-start-test-driven-development-with-test-explorer.md)
0 commit comments