All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.tech.apter.junit.jupiter.robolectric.internal.RobolectricClassLoaderFactory.kt Maven / Gradle / Ivy

Go to download

This repository aims to bridge the gap between JUnit 5 and Robolectric, enabling developers to leverage the benefits of both frameworks for unit testing Android applications. While Robolectric currently lacks a dedicated JUnit 5 extension, this project proposes a community-driven solution to achieve seamless integration.

The newest version!
package tech.apter.junit.jupiter.robolectric.internal

import tech.apter.junit.jupiter.robolectric.internal.extensions.isJUnit5NestedTest
import tech.apter.junit.jupiter.robolectric.internal.extensions.nearestOuterNestedTestOrOuterMostDeclaringClass

internal fun robolectricClassLoaderFactory(testClass: Class<*>): ClassLoader {
    val testClassForRunner = if (testClass.kotlin.isCompanion) {
        testClass.declaringClass
    } else if (testClass.isJUnit5NestedTest) {
        testClass
    } else if (testClass.declaringClass != null) {
        testClass.nearestOuterNestedTestOrOuterMostDeclaringClass()
    } else {
        testClass
    }

    val testRunnerHelper = JUnit5RobolectricTestRunnerHelper.getInstance(testClassForRunner)
    return testRunnerHelper.sdkEnvironment(null).robolectricClassLoader
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy