The first test, let's reverse a string!
Video

Formulation of the problem: we need a class that takes a string and returns the same symbols in reverse order. Let's create a console project FirstTest and add a class named StringReverser to it.

public class StringReverser
{
    public string Reverse(string input)
    {
        return string.Empty;
    }
}

Than we should create another project in the same solution with the name FirstTestTests and add the required libraries. Here we will look at nUnit and xUnit simultaneously, just not to repeat the same things in two separate articles. In the future, we probably will describe work with one library in an article.

Create a first testing class with the name StringReverserTests. Such naming - Tests is a common tradition and I would recommend you to follow that practice. It is much better than trying to think up specific naming for every situation.

Meanwhile, we can find out the first difference in syntax of the libraries: nUnit needs a special attribute [TestFixture] to recognize a testing class, xUnit doesn't require such nicety.

public class StringReverserTests{}

And the testing method itself:

  [Test]
  public void Reverse_Success()
  {
    var input = "text";
    var expected = "txet";
    var reverser = new StringReverser();
    //
    var result = reverser.Reverse(input);
    //
    Assert.True(result == expected);
  }
  [Fact]
  public void Reverse_Success()
  {
    var input = "text";
    var expected = "txet";
    var reverser = new StringReverser();
    //
    var result = reverser.Reverse(input);
    //
    Assert.True(result == expected);
 }

Don't miss the attributes Test/Fact, they show the system that those methods are the testing ones. Without those attributes, the tests will not launch.

Every test consists of three parts: data preparation, calling the testing method, and the result examination. I believe the code here speaks for himself, but... Let's clear it a little bit. Because we need to check the Reverse method of the class StringReverser, we definitely need an instance of the class. Next step - the string that should be reversed (input) and, in the end, the expected result to compare with.

The Assert method. It is responsible for checking the statement inside(result == expected). It is not hard to guess that Assert.True() means we expect the statement to be true. Also, we can use Assert.False() in other cases and a big number of other helpful methods that will appear in the next articles.

If you are a happy owner of the Rider or the ReSharper, press Ctrl+T,L. In a 'clean' Visual Studio - Ctrl+T,A. Or, if you prefer old-school methods, you can try to find the button "Run all tests" somewhere in the menu.

As a result, we see the red line - test felt down. Not a surprise, yeah? The functionality of the Reverse method wasn't implemented and it always returns an empty string. I leave the implementation of the method to the reader's conscience) Make the test pass and move on - parameterized tests are waiting for us!