typestar

Facts in C#

A test is a method with an attribute; xunit finds the rest.

using Xunit;

public class TokenizerTests
{
    [Fact]
    public void Splits_on_spaces()
    {
        var tokens = "var x = 5".Split(' ');
        Assert.Equal(4, tokens.Length);
        Assert.Equal("var", tokens[0]);
    }

    [Fact]
    public void Empty_input_yields_one_empty_token()
    {
        Assert.Single("".Split(' '));
    }
}

How it works

  1. [Fact] marks a test that takes no arguments.
  2. Assert.Equal and Assert.Single state the expectations.
  3. Test names in words double as documentation.

Keywords and builtins used here

The run, in numbers

Lines
18
Characters to type
279
Tokens
69
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 46 seconds.

Type this snippet

Step 1 of 3 in Testing, step 10 of 16 in The open ecosystem.

← Previous Next →