I am trying to come to terms with the new unit test feature in Android Studio. I followed the instructions http://tools.android.com/tech-docs/unit-testing-support . In the description, the error "Method ... not maceded" is explicitly mentioned there and it is proposed to put the following in build.gradle :
android { // ... testOptions { unitTests.returnDefaultValues = true } }
This works because tests are run when launched from the command line using
gradlew test --continue
but not when I run the test class from Android Studio using rightclick β run. So I get the same error again:
java.lang.RuntimeException: Method setUp in android.test.AndroidTestCase not mocked. See https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support for details. at android.test.AndroidTestCase.setUp(AndroidTestCase.java) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Any ideas on how to solve this?
EDIT: the contents of the test class does not matter much because the setUp of the test does not work, I tried with the simplest class:
public class ContactFormToolTest extends AndroidTestCase { public void testSOmething(){ assertEquals(false, true); } }
Also tried overriding setUp, it doesn't matter.
android android-studio unit-testing
Fweigl
source share