Broken Unit Test Runner in Android Studio Ladybug 2024.2.1

Broken Unit Test Runner in Android Studio Ladybug 2024.2.1

It's almost midnight and I'm close to wrapping up my test cases. But when I thought everything was set, I hit an error: java.lang.NoClassDefFoundError. My unit test just won’t run. Classes outside the “test” source set aren’t initializing in Android Studio, and nothing seems to fix it.

Hours tick by as I dig into dependencies, trying to spot any recent changes, but I find nothing. Then, I remember the only change this week: I updated Android Studio from Koala Drop to Ladybug.

After some searching, I finally found a topic on the Google Issue Tracker where others are facing the same issue. Unfortunately, the patch hasn’t been released yet. But there’s a workaround mentioned there, and after testing it, I can confirm it works.

If you’re dealing with this same problem, here’s how to save yourself some serious frustration:


The Workaround

  • Open your runConfigurations.xml file (found in .idea/runConfigurations).
  • Replace its content with the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="RunConfigurationProducerService">
    <option name="ignoredProducers">
      <set>
        <option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
        <option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
        <option value="com.intellij.execution.junit.PatternConfigurationProducer" />
        <option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
        <option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
        <option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
        <option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
        <option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
      </set>
    </option>
  </component>
</project>        

  • Close the project and reopen it.

That’s it! The issue seems to occur only when running unit tests from Android Studio’s GUI, while tests pass without issues when executed directly through Gradle.


Hope this saves you hours of troubleshooting!

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics