Component (service) testing

Component or service testing is a method where we bypass the UI and directly test the API (in our case, the ASP.NET Core Web API). Using this test, we confirm that an individual service does not have any code bugs or that it is working fine functionality-wise.

Testing a service does not mean it is an independent service. This service might be interacting with an external service. In such a scenario, we should not call the actual service but use the mock and stub approach. The reason for this is our motto to test code and make sure it is bug-free. In our case, we will use the moq framework for mocking our services.

There are a few things worth to be noted in the case of component or service testing:

  • As we need ...

Get Building Microservices with .NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.