/modb-test

This lib contains all essential dependencies as well as some convenience functions and classes for creating tests in modb prefixed kotlin projects.

Primary LanguageKotlinGNU Affero General Public License v3.0AGPL-3.0

Tests codecov jdk21

modb-test

modb stands for Manami Offline DataBase. Repositories prefixed with this acronym are used to create the manami-project/anime-offline-database.

What does this lib do?

This lib contains all essential dependencies as well as some convenience functions and classes for creating tests in modb prefixed kotlin projects.

Features

essential test dependencies

  • junit5
  • kotlin-test for junit5
  • assertj
  • wiremock

easy access to test resources

// access to a file in src/test/resources
val file: Path = testResource("file.txt") // for src/test/resources/file.txt
val file: Path = testResource("dir/subdir/file.txt") // for src/test/resources/dir/subdir/file.txt

// reading the content of a file in src/test/resources into a String
val fileContent: String = loadTestResource("file.txt") // for src/test/resources/file.txt
val fileContent: String = loadTestResource("dir/subdir/file.txt") // for src/test/resources/dir/subdir/file.txt

temporary directory

Creates a temporary directory and ensures that it will be deleted after test execution even if the test fails due to an exception.

tempDirectory {
    Files.exist(tempDir)
}

mock server test cases

Create mock server test cases.

internal class SampleTest : MockServerTestCase<WireMockServer> by WireMockServerCreator() {

    @Test
    fun `test case`() {
        serverInstance.stubFor(
            head(urlPathEqualTo("/test")).willReturn(
                    aResponse()
                        .withHeader("Content-Type", "text/plain")
                        .withStatus(200)
            )
        )
    }
}