Open Closed

Unit testing Daper repository not working #8809


User avatar
0
Yaduraj.Shakti created

We have recently started using Daper with EF Core. Our unit tests are written based on previous implementation of EF Core and using default SQLLite.
Now we want to test our repository and dependent unit tests but it gives error like Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: 'no such table: public.MyTables.

I have reviewed daper documentation and there are no details on unit testing and also checked the DaperDemo. https://github.com/abpframework/abp-samples/tree/master/Dapper/DapperDemo

Please can you help with a sample on how to unit tests code or repository that using daper. Thanks

  • ABP Framework version: v8.3.0

  • UI Type: Angular

  • Database System: EF Core (PostgreSQL) and Daper

  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

  • Exception message and full stack trace: No Such Table found

  • Steps to reproduce the issue:
    Write unit test that calls the Daper repository to access seeded data.


1 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Unit tests are configured to execute all the migrations and data seeds initially by default.

    Do you have required migrations for your custom tables in the project?

    Even you don't use EF query, you can still add your custom tables to the DbContext and create migrations to apply database scheme to the database. This is the easiest way to create tables in the test environment.

    Otherwise, you can customize your test module and add custom sceheme migration logic in the OnApplicationInitialization method.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 19, 2025, 10:09