Android Unit Testing / Mockito: android.location.Location not mocked -


i trying learn basic junit , mockito testing on android. i'm trying write unit tests simple class handles finding user's location location services on behalf of activities need location information.

i have been trying create "faked location" test with:

@test public void testlocationreceived() throws exception {     location fakelocation = new location(locationmanager.network_provider);     fakelocation.setlongitude(100);     fakelocation.setlatitude(-80);     ...   } 

but error:

java.lang.runtimeexception: method setlongitude in android.location.location not mocked. 

i understand unit tests on android run on jvm, don't have access requires operating system / framework, 1 of cases well?

  • if so, how tell classes can / can't used on jvm?
  • do need instrumentation/device tests in addition jvm-based unit tests test 1 class?

you should add following in build.gradle (app):

testoptions {         unittests.returndefaultvalues = true } 

more detail: http://tools.android.com/tech-docs/unit-testing-support#toc-method-...-not-mocked.-


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -