Sorry, I failed to really understand the new feature and failed to explain why my old tests failed. After the update, all my InstrumentationTestCases because getInstrumentation() returned null and I couldn't get a Context. The reason for this I do not know. I changed all those tests to AndroidTestCase and now they work again.
One more question though: is it possibly to get a Context and to access Resources (Strings, Assets etc) from tests run under the new feature (without device)? People claim they could on Stackoverflow <http://stackoverflow.com/questions/28960898/getting-context-in-androidtestcase-or-instrumentationtestcase-in-android-studio> but I couldn't. Am Donnerstag, 19. März 2015 02:42:03 UTC+1 schrieb Michal Bendowski: > > Hi Florian, > > The unit testing support is not meant to replace running tests on a > device, they allow you to write a new kind of tests with a shorter > iteration time. Most likely, you won't be able to easily convert your > existing tests to unit tests that mock out all the platform code. > > So in short: you should still be running your tests the "old" way. What > exactly is the problem after the upgrade? Can you file a bug at > b.android.com? > > Thanks, > > Michal > > On Wed, Mar 18, 2015 at 2:56 PM florian weigl <[email protected] > <javascript:>> wrote: > >> I had my test setup as follows: >> >> Tests in the src/androidTest folder, Run Configuration 'Android tests', >> all in module, no specific TestRunner set (Pic1). >> Running my configuration brought up the Run view (shown in Pic2 without >> running tests) and the tests were run on a connected device, same for >> starting the tests with >> gradlew connectedCheck >> >> After the update to 1.1.0 and the introduction of the new 'unit test >> feature' none of my tests worked the old way. I tried to get them running >> the new way following this >> http://tools.android.com/tech-docs/unit-testing-support guide. >> I have the following problems with this: >> >> 1. When started from the IDE with rightclick -> run, I receive the error >> message >> >> java.lang.RuntimeException: Method getInstrumentation in android.test. >> InstrumentationTestCase not mocked. See https:// >> sites.google.com/a/android.com/tools/tech-docs/unit-testing-support for >> details. >> at android.test.InstrumentationTestCase.getInstrumentation( >> InstrumentationTestCase.java) >> at CriterionTemplateTest.setUp(CriterionTemplateTest.java:32) >> >> although I explicitly added >> >> android { >> // ... >> testOptions { >> unitTests.returnDefaultValues = true >> } >> } >> >> to my build.gradle as advised in the guide. >> >> 2. When I run the tests from the command line with >> gradlew testDebug >> >> the tests do run, most of them throw an exception though because >> getContext() // in AndroidTestCase >> >> and >> >> getInstrumentation().getContext() // in InstrumentationTestCase >> >> both return null, so I don't have a Context and can't access my >> Resources. I tried using >> new Activity() >> >> >> as Context, but it also fails to provide the Resources. >> >> So I tried getting back to the old ways of running tests on a device. I >> explicitly set the test folder to the old convention of /src/androidTest >> with >> sourceSets{ >> test{ >> java.srcDirs = ['src/androidTest'] >> } >> } >> >> use my old build.gradle and Run Configuration. Running this Run >> Configuration fires up the view of Pic2, but tells me that I have an >> empty test suite >> >> this not running my tests. >> >> So first of all it would be nice if updates to AS would not break working >> configurations without prior warning, especially since it is now put of >> beta and the official development tool. >> >> Second of all: do you guys have any ideas on how I can get my tests back >> to work with full access to the projects resources, assets etc. ? Either >> the old or the new way. >> >> Best regards, Florian >> >> >> >> >> Pic 1: >> Pic2: >> >> >> <https://lh4.googleusercontent.com/-2LkgN0o4Sfc/VQHAlX9Fs8I/AAAAAAAAD1Y/2BoQ7MT_Z9U/s1600/empty.png> >> >> <https://lh3.googleusercontent.com/-y4dEbyNumDY/VQG5vTpY3HI/AAAAAAAAD1I/vaXSNw1jIlc/s1600/runconfig.png> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "adt-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "adt-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
