The Given3ThenFizz test

The first test method in the UnitTest1.cs file is named Test1. Let's change the name of this method to Given3ThenFizz and write our first test:

[Fact]
public void Given3ThenFizz()
{
// Arrange
// Act
var result = FizzBuzz(3);

// Assert
Assert.Equal("Fizz", result);
}

Note that the Fact attribute and Assert.Equal assertion differ only slightly from our previous MSTest example. We're leaving the Arrange, Act, and Assert comments in place, and recommend you do the same. These comments will help you as you get started. They'll also serve to help describe the process to any developers that come behind you in the future.

Now, run the test to see whether it passes by selecting Run | All Tests from the Test menu, or by using the shortcut keys (Ctrl + R, A). You should see a compilation error. Let's resolve the error by creating a FizzBuzz method preceding our test class. Once you've created the FizzBuzz method, rerun your test to see it pass. Remember, based on the third law of TDD, you should only write enough code to make it pass:

private object FizzBuzz(int value)
{
return "Fizz";
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.162.204