Writing tests
Time to write some tests. As I mentioned earlier in the chapter, we won't create tests for the entire site; we will leave that to you to finish later if you want to. This is just to get a feel for how to write tests:
- Right-click and select MyBlog.Shared.Tests, then select Add | New folder. Name the folder
Pages
.This is just so we can keep a bit of a structure (the same folder structure as the project we are testing).
- Select the
Pages
folder. Press Shift + F2 to create a new Razor component and name the fileIndexTest.cs
. Just remember not to name it the same as the component we are testing; otherwise, it will be hard to make sure we are testing the right one. - Open
IndexTest.cs
and add the bUnit namespace:using Bunit; using Microsoft.Extensions.DependencyInjection; using MyBlog.Data.Interfaces; using Xunit;
- Inherit from
TestContext
by adding the following code:    public class IndexTest: TestContext     ...