3

Upgrading your Android Studio to Arctic Fox will cause you to go back and make adjustments to your build as documented here: Junit5 testSuite with SelectClasses not working in android unit test

Does that mean I have to adjust all my unit tests from using JUnit 4?

Lance Kind
  • 949
  • 12
  • 32

1 Answers1

3

Yes. The JUnit4 runtime (Test Runner) isn't compatible. If you don't switch your tests to using Junit Jupiter, you'll receive "test events not received" when telling a test class to execute.

enter image description here

Another wrinkle is to realize that Roboelectric doesn't work with Jupiter. For those tests, you'll still need to use the JUnit 4 @Test and have Jupiter's vintage test runner in your dependencies: How to run a Junit5 test with Android dependencies and robolectric

Summary of gradle build changes:

android {
testOptions {
    execution 'ANDROIDX_TEST_ORCHESTRATOR'
    unitTests.all {
        useJUnitPlatform() // <--- this is the important part
    }
}

And for dependencies:

 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)
}
Lance Kind
  • 949
  • 12
  • 32