Home > Software engineering >  Using Jupiter(Junit5) on instrumentation tests
Using Jupiter(Junit5) on instrumentation tests

Time:07-28

I want to use Junit5 on instrumentation tests.
When I add this line to Build.gradle

androidTestImplementation "org.junit.jupiter:junit-jupiter:$junit_jupiter"

My test showed the below error

FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':android_test:mergeDebugAndroidTestJavaResource'.
> A failure occurred while executing 
com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
> 6 files found with path 'META-INF/LICENSE.md' from inputs:
  - C:\Users\Ali\.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter- 
params\5.8.2\ddeafe92fc263f895bfb73ffeca7fd56e23c2cce\junit-jupiter-params-5.8.2.jar
  - C:\Users\Ali\.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter- 
engine\5.8.2\c598b4328d2f397194d11df3b1648d68d7d990e3\junit-jupiter-engine-5.8.2.jar
  - C:\Users\Ali\.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter- 
api\5.8.2\4c21029217adf07e4c0d0c5e192b6bf610c94bdc\junit-jupiter-api-5.8.2.jar
  - C:\Users\Ali\.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform- 
engine\1.8.2\b737de09f19864bd136805c84df7999a142fec29\junit-platform-engine-1.8.2.jar
  - C:\Users\Ali\.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform- 
commons\1.8.2\32c8b8617c1342376fd5af2053da6410d8866861\junit-platform-commons-1.8.2.jar
  - C:\Users\Ali\.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit- 
jupiter\5.8.2\5a817b1e63f1217e5c586090c45e681281f097ad\junit-jupiter-5.8.2.jar
 Adding a packagingOptions block may help, please refer to
 https://developer.android.com/reference/tools/gradle- 
api/7.2/com/android/build/api/dsl/ResourcesPackagingOptions

I searched and find a new dependency witch published by mannodermaus.de
It is below dependencies

  androidTestImplementation("de.mannodermaus.junit5:android-test-core:1.3.0")
  androidTestRuntimeOnly("de.mannodermaus.junit5:android-test-runner:1.3.0")

But I prefer to use official dependencies.

question: Do you have any idea to use junit5(jupiter) in the instrumentation tests(androidTest folder)?

CodePudding user response:

You could use exclude to ignore mentioned files by editing gradle file:

android {
    compileSdkVersion("android-31")

    defaultConfig {
        minSdk = 26
        targetSdk = 32
        //...
    }

    lintOptions {
        // ....
    }

    packagingOptions {
        exclude("META-INF/LICENSE.md")
        exclude("META-INF/LICENSE-notice.md")
    }
    
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

Or you can find a sample of solution here.

  • Related