← All articles
development

Android Studio Espresso 2.0 ClassNotFoundException

Espresso 2.0 throwing ClassNotFoundException in an app that also uses Dagger? Exclude the javax.inject group from the espresso-core dependency.

Donn Felker

Donn Felker

2015.01.13 · 1 min read

File this under “I’m writing this so when I Google for it in 6 months, it pops up”. 

I recently set up an existing Android project with Espresso 2.0 and immediately stared running into this error when I ran the tests: 

Terminal window
Running tests
Test running started
Test running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
Empty test suite.

I spent some time last night fighting this error and then I figured out the solution this morning.

The problem is that I’m using Dagger in this project and Espresso 2.0 also uses Dagger (see Espresso Dependencies). The core problem is that the ‘javax.inject’ dependency was borking the test run. 

How to to Fix

Change this

androidTestCompile('com.android.support.test.espresso:espresso-core:2.0')

to this: 

androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') {
  exclude group: 'javax.inject'
}

Problem solved.

Donn Felker

Written by Donn Felker

I've spent 25+ years shipping software, writing books, and running my own companies. I write about thinking clearly, working for yourself, and doing real work while AI rewrites the rules. New essays land here every week.

Get the newsletter

Keep reading