I'm trying to verify that my code that interacts with a WebView control is properly passing Javascript calls into the WebView, but my unit tests are not executing correctly. It looks like maybe the tests are running against the wrong version of Android.
My test:
@Test
public void testJavascript() {
// myObj will pass its argument as a string to a WebView control referenced in the
// test as mWebView
myObj.callJavascript("some code"); // passes to a WebView control
// Using Mockito to verify calls to mocked WebView
verify(mWebView).evaluateJavascript(anyString(), any(ValueCallback.class));
}
I'm building with a target of Android 4.4, using Gradle for my build system. I'm new to Gradle and may be screwing something up. As far as I can tell, Maven Central does not have Android 4.4 up, so I'm using the local .jar file from my Android Studio install.
from build.gradle:
android {
compileSdkVersion 19
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
}
sourceSets {
unitTest {
java.srcDir file('src/test/java')
resources.srcDir file('src/test/res')
}
}
configurations {
unitTestCompile.extendsFrom runTime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
unitTestCompile files("$project.buildDir/classes/release")
unitTestCompile 'junit:junit:4.11'
unitTestCompile 'org.robolectric:robolectric:2.2'
unitTestCompile 'org.mockito:mockito-core:1.9.5'
unitTestCompile files('../libs/android-19.jar') // From Android Studio
}
task unitTest(type:Test, dependsOn:assemble) {
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
check.dependsOn unitTest
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Tests.class"
}
When I try to run my test via gradle unitTest
I get an error that I can't make sense of:
com.example.Tests > testCallJavascript FAILED
java.lang.NoSuchMethodError: android.webkit.WebView.evaluateJavascript(Ljava/lang/String;Landroid/webkit/ValueCallback;)V
at com.exampleTests.testCallJavascript(Tests.java:...)
UPDATE:
Okay, after adding a debug println to check the version of the SDK that the tests are running against, it looks like they're running against APILEVEL 14, which does not support WebView.evaluateJavascript(). As far as I can tell, I have never configured this project to target APILEVEL 14. And ideas where I should be looking to figure out what is configured wrong? Thanks!