Writing tests
It’s 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:
- In the
MyBlog.Tests
project, create a new folder calledPages
. 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 and create a new Razor component calledHomeTest.razor
. - In the
_Imports
file, add the following namespaces:@using SharedComponents.Pages @using Data.Models.Interfaces @using SharedComponents.ReusableComponents
- In the
HomeTest.razor
file, inherit fromTestContext
by adding the following code:@inherits TestContext
- Now, we will add the test. Add the following code:
@code{ [Fact(DisplayName ="Checks that the Home component shows 10 posts")] public void Shows10Blogposts...