androidunit-testinggradleandroid-studiofest

Android FEST not compiling properly for unit tests in IDE


For some reason, Android Studio is not properly compiling the Android FEST library (?).

This line,

assertThat(someView).isNotVisible();

causes this exception to be thrown:

java.lang.UnsupportedClassVersionError: org/fest/assertions/api/ANDROID : Unsupported major.minor version 51.0

and the import that i used is: import static org.fest.assertions.api.ANDROID.assertThat;

What's going on?

Oh, and it should be noted that the gradle task to run unit tests run just fine (but just not for IDE).


Solution

  • THis means that the library was compiled with a later version of Java than what you're using to do builds in the IDE. v51.0 is Java 7, so you need to have JDK 7 available and set Android Studio to use it via Project Structure > SDK location.

    Note that you don't need to run the IDE itself using Java 7 if you don't want, and you don't have to turn on Java 7 compatibility in your projects; you just need to use Java 7 to do the builds themselves.