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
[Fact]marks a test that takes no arguments.Assert.EqualandAssert.Singlestate the expectations.- Test names in words double as documentation.
Keywords and builtins used here
Empty_input_yields_one_empty_tokenSplits_on_spacesTokenizerTestsclasspublicusingvarvoid
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.
Step 1 of 3 in Testing, step 10 of 16 in The open ecosystem.