# How to use an in-memory database for testing on Ktor

DevFeed: [How to use an in-memory database for testing on Ktor](<https://devfeed.tech/articles/how-to-use-an-in-memory-database-for-testing-on-ktor-25560.md>)

Original publisher: [Read original article](<https://www.marcogomiero.com/posts/2021/ktor-in-memory-db-testing/>)

Author: Marco Gomiero

Published: 2021-10-04T00:00:00Z

Content type: tutorial

Language: en

Sources: [Posts on Marco Gomiero](<https://devfeed.tech/sources/posts-on-marco-gomiero.md>)

Topics: [Ktor](<https://devfeed.tech/topics/ktor.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [backend-development](<https://devfeed.tech/topics/backend-development.md>)

Tags: [database](<https://devfeed.tech/tags/database.md>), [in-memory-database](<https://devfeed.tech/tags/in-memory-database.md>), [jetbrains](<https://devfeed.tech/tags/jetbrains.md>), [ktor](<https://devfeed.tech/tags/ktor.md>), [mysql](<https://devfeed.tech/tags/mysql.md>), [orm](<https://devfeed.tech/tags/orm.md>), [testing](<https://devfeed.tech/tags/testing.md>)

## AI overview

This tutorial explains how to use an H2 in-memory database for automated testing in a Ktor backend project that uses MySQL in production. It discusses clearing test data, using Docker as an alternative, and configuring the Exposed ORM.

## Source excerpt

SERIES: Building a backend with Ktor Part 1: Structuring a Ktor project Part 2: How to persist Ktor logs Part 3: How to use an in-memory database for testing on Ktor Part 4: How to handle database migrations with Liquibase on Ktor Part 5 Generate API documentation from Swagger on Ktor Part 6: How to schedule jobs with Quartz on Ktor Part 7: Moving from mobile to backend development with Ktor Usually, in a backend project, there are different instances of the same database: one for production (or more than one, it depends on the architecture), one for staging, and a local one that runs in the development machine.