spek icon indicating copy to clipboard operation
spek copied to clipboard

Spek Framework IJ/Android Studio Runner in Android Studio puts android.jar first in class path

Open orospakr opened this issue 6 years ago • 4 comments

With the JVM, classpath entries that appear first in the list given to -classpath take precedence.

However, the Spek Framework runner in IntelliJ/Android Studio appears to put android.jar first in the classpath.

For example:

Testing started at 14:37 ...
"/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java" \
"-javaagent:/Applications/Android Studio.app/Contents/lib/idea_rt.jar=53633:/Applications/Android Studio.app/Contents/bin" \
-Dfile.encoding=UTF-8 \
-classpath "/Users/andrew/Library/Android/sdk/platforms/android-27/android.jar:<library-and-project-jars-follow...>" \
org.spekframework.ide.ConsoleKt --sourceDirs <...and so on...> 

(newlines added for clarity)

This can be bit problematic if one is using classpath ordering as an escape valve from Android's stub implementations of things. org.json particularly, in my case.

As such, if you're using testImplementation 'org.json:json:20180130' or similar to shadow android.jar's stubbed version of org.json (or something similar) in your specs, results in:

Stub!
java.lang.RuntimeException: Stub!
	at org.json.JSONObject.<init>(JSONObject.java:23)

This problem does not occur if you use the test gradle target, eg., ./gradlew test.

Versions:

Spek Framework: 2.0.2 Android Studio 3.3.2 Build #AI-182.5107.16.33.5314842, built on February 15, 2019 JRE: 1.8.0_152-release-1248-b01 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.14.3 Spek Framework IJ plugin: 2.0.2-IJ2018.2

orospakr avatar Apr 08 '19 19:04 orospakr

Not sure on how to fix this, the classpath the plugin uses is provided by AS itself. Do you have the same problem if you run a JUnit 4 test in AS?

raniejade avatar Apr 09 '19 06:04 raniejade

Yeah, that's my current workaround: if I run it with the classic JUnit test run configuration, my overlay of org.json just works.

orospakr avatar Apr 09 '19 18:04 orospakr

Actually, android.jar should not be in the classpath - the plugin has some special logic to remove android jars and replace them with mockable versions.

raniejade avatar Apr 13 '19 00:04 raniejade

@orospakr is this still an issue with AS 3.4? Tested it on a project and it puts android.jar at the end of the classpath.

raniejade avatar Apr 27 '19 11:04 raniejade