Skip to main content
Accessing test resources in Kotlin Multiplatform can be tricky. FileKit provides a simple solution with FileKit.projectDir.

The Problem

In KMP, there’s no built-in way to access files in your test resources folder across all platforms. Traditional approaches like ClassLoader.getResource() don’t work consistently.

The Solution

FileKit provides FileKit.projectDir which returns the root directory of your project. From there, you can easily navigate to your test resources:

Example

Here’s a complete example of a multiplatform test that reads a file from test resources:

Project Structure

Your test resources should be placed in the appropriate source set:
Use the / operator (via div) to build paths in a readable way:

Supported Platforms

FileKit.projectDir is available on all non-web platforms: