I have looked through answers related to this but they don't seem to solve my problem.
I am fairly new unit testing and testing as a whole. I just finished a small web application using ASP.NET Core MVC and I wanted to write tests for the projects. I am using xUnit and Moq.
The project has a business logic layer that contains the business logic for the app.
I am writing tests for the Controllers, but the Controllers contains mostly CRUD operations that use the Repository layer. My tests for the controller involves using an in-memory database since that is the recommended way for ASP.NET Core MVC.
However, I feel what I am doing is no longer unit tests but integration tests since I am testing against a database.
I had thought of writing integration tests for the Repository layer and then unit test for the controllers such that the controllers would not have to check for database operations.
I want to know if this is the right way to go or if there is any other way.
Thanks. [Edit]. Thanks @greg-burghardt for the reply. I made a mistake in my question, I actually meant to write that I have a business logic layer. Also I am using EF, and I believe that takes care of the Repository. My Controllers use the Interface of the required BLL. Example
public class PaymentController : ControllerBase
private readonly IConfiguration _config;
private readonly IPaymentsBL _paymentsBL;
private readonly ILogger _logger;
public PaymentsController(IConfiguration config, IPaymentsBL paymentsBL, ILogger<PaymentsController> logger)
_config = config;
_paymentsBL = paymentsBL;
_logger = logger;
And the implementation,
public class PaymentsBL : GenericBL<MPayments>, IPaymentsBL
private readonly WellaPatientDbContext _db;
public PaymentsBL(WellaPatientDbContext db)
_db = db;
public IQueryable<MPayments> GetByPatientId(Guid id)
return _db.MPayments.Where(x => x.PaymentId == id);
Also, you said I am hitting a real database with my tests. I dont understand since I am using an in-memory database.
So if I get you right, tests for the business logic layer is the most important. Thanks