Reputation: 121
Recently I upgraded my JUnit 4 runner from androidx.test.runner.AndroidJUnit4 to androidx.test.ext.junit.runners.AndroidJUnit4.
When I execute the test i get the following error: Test running failed:
Instrumentation run failed due to 'Process crashed.'
The LogCat shows this error:
java.lang.InstantiationException:
java.lang.Class<androidx.test.ext.junit.runners.AndroidJUnit4> has no zero argument constructor
All the imports in the test are correct and I'm not getting any error in the build.
My app gradle look like this:
defaultConfig {
testInstrumentationRunner 'androidx.test.ext.junit.runners.AndroidJUnit4'
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation "androidx.test.ext:junit:1.1.0"
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Upvotes: 5
Views: 4519
Reputation: 161
Add this line to module's build.gradle
file:
androidTestImplementation 'androidx.test.ext:junit:<version>'
Upvotes: 1
Reputation: 21
When I imported below code:
import org.junit.Test;
it solved my error.
Upvotes: 0
Reputation: 1118
try
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
in place of
testInstrumentationRunner 'androidx.test.ext.junit.runners.AndroidJUnit4'
Upvotes: 10