AS升级arctic fox后报Test events were not received
1. 使用 Android Studio Arctic fox 要使用JUnit5 测试,需要添加一些依赖项:junit-platform-launcher、junit-platform-engine等测试类中的@Test导入为import org.junit.jupiter.api.Test
gradle build:
android {
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
unitTests.all {
useJUnitPlatform() // <--- this is the important part
}
}
依赖:
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
//testImplementation 'junit:junit:4.+'// should get rid of this old JUnit.
testImplementation 'org.junit.vintage:junit-vintage-engine' //Let's Jupiter do the right thing when encountering a @RunWith(RobolectricTestRunner::class)
}
https://stackoverflow.com/questions/68851779/android-studio-arctic-fox-incompatible-with-junit4
2. 若仍有Test events were not received报错
可能是由于jacoco而发生的。最新的 Android Studio Arctic fox 带有 Java 11,但我们使用的是 Java 1.8(或其他低版本)。需要添加:
jacoco.excludes = ['jdk.internal.*']
https://stackoverflow.com/questions/68737413/noclassdeffounderror-on-running-unit-test-after-updating-android-studio-to-artic
页:
[1]