Integration Testing in Dotnet With InMemory Db

Integration testing is a software testing technique, where individual units of a program are integrated together and tested as a group for interacting harmoniously with each other. It concerns the testing of interactions and interfaces between modules, components, or systems to see if they behave as expected once integrated.

📢 Always use real database for integration testing instead of InMemory Db.

Purpose

  • This is to ensure that various components or modules behave according to expectation.
  • In the case of integration, to find out whether there are problems concerning interfaces or inconsistencies in data.
  • Verifying whether it meets the set specifications and functionality of an integrated system.

Tech Used in this project

  • .Net 8 web APIs (controller)
  • Sqlite
  • EntityFrameworkCore
  • xUnit
  • In Memory Database (for testing)

Let’s get started

Create a sln file (I have named it PersonGithubActionsDemo) with two projects

[Read More]

Unit Testing in Dotnet Core With Nsubstitute

As the name suggesting , Unit testing is a software testing where smallest units of the application such as methods are tested in the isolation, so that we can ensure our software is working as expected.

Commonly used testing frameworks

  • MSTest
  • nUnit
  • xUnit

Mocking frameworks

Mocking framework is a library which allows us to mock the objects. For example, a PeopleController is injected with the IPersonRepository. While testing the PeopleController, we need the IPersonRepository. Mock frameworks comes to rescue in that situation. With the help of mock frameworks we can mock the IPersonRepository and mimic it’s behavior. Some popular mocking libraries are:

[Read More]