-
Book Overview & Buying
-
Table Of Contents
Web Development with Blazor - Fourth Edition
By :
There are different ways to test our application.
Testing the API is beyond the scope of this book, but we still need to test the components that depend on it. We could spin up the API and test against it, but in this case, we are only interested in testing the Blazor component.
Instead, we can mock the API or create a fake version that doesn't read from the database but instead reads from a predefined dataset. This way, we always know what the output should be.
Luckily, the interface we created for our API is all we need to build a mock API.
We won't implement 100% of the project's tests, so we don't need to mock all the methods. Please feel free to implement tests for all methods as an end-of-chapter exercise.
There are two ways we can implement the mock API: one option is to spin up an in-memory database, but to keep things simple, instead, we will generate posts when we ask for them:
MyBlog.Tests project, add a project reference to the...