Add new tests for app hiding

This commit is contained in:
topjohnwu
2024-12-17 22:11:01 -08:00
committed by John Wu
parent 820710c086
commit 5885b8c20d
15 changed files with 271 additions and 168 deletions

View File

@@ -9,7 +9,7 @@
</application>
<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:name="com.topjohnwu.magisk.test.TestRunner"
android:targetPackage="com.topjohnwu.magisk"
android:label="Tests for Magisk" />

View File

@@ -1,29 +0,0 @@
package com.topjohnwu.magisk.test
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.topjohnwu.magisk.core.TestImpl
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class Environment {
companion object {
@BeforeClass
@JvmStatic
fun before() {
TestImpl.before()
}
}
@Test
fun setupMagisk() {
TestImpl.setupMagisk()
}
@Test
fun setupShellGrantTest() {
TestImpl.setupShellGrantTest()
}
}

View File

@@ -1,24 +0,0 @@
package com.topjohnwu.magisk.test
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.topjohnwu.magisk.core.TestImpl
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class MagiskAppTest {
companion object {
@BeforeClass
@JvmStatic
fun before() {
TestImpl.before()
}
}
@Test
fun testZygisk() {
TestImpl.testZygisk()
}
}

View File

@@ -0,0 +1,18 @@
package com.topjohnwu.magisk.test
import android.os.Bundle
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.runner.AndroidJUnitRunner
class TestRunner : AndroidJUnitRunner() {
override fun onCreate(arguments: Bundle) {
// Force using the target context's classloader to run tests
arguments.putString("classLoader", TestClassLoader::class.java.name)
super.onCreate(arguments)
}
}
private val targetClassLoader inline get() =
InstrumentationRegistry.getInstrumentation().targetContext.classLoader
class TestClassLoader : ClassLoader(targetClassLoader)