Wednesday, 15 September 2010

Unit testing on Android Studio: "not mocked" error -


I am new to Android studio, I have previewed the Android Studio 1.2, Graduate 2.2.1 and Crowdell Plugin 1.1.0 I am using.

  java.lang.RuntimeException: method getInstrumentation in android.test  

I can not find this error around: code>

This is my test class:

  extends the public class AppPreferencesTest instrumentation preferences (AppPreferences preferences); @private zero setup () throws an exception before {preferences = new AppPreferences (getInstrumentation (). GetTargetContext ()); } ...  

In my build.gradle:

  testcompile 'junit: junit: 4.12'  

I tried to add this

  testOptions {unitTests.returnDefaultValues ​​= true}  

because at that stage I had followed it but it was fine does not .

I also tried to create a mock contact:

  Preferences = New AppPreferences (new MockContext ());  

but gives an error to the creator of AppPreferences

  Public AppPreferences (reference references) {preferences = PreferenceManager.getDefaultSharedPreferences (reference); }  

...

  Runtime Expansion: The method getDefaultSharedPreferences in Android.PreferenceManager is not joke.  

I think you have updated your question.

Please take a look at this source of shared contexts. Mask. Java :. Here is an exam:

Here's a snippet that shows how they made their mock:

  @ Override protected zero set-up () Exceptions thrown {Last shared reference maskContache Mock CONTEX = New shared referencesMocContext ()); Mock Application Mock Uppication = New Mock Uppication () {@ Override Public Context Text AppLogging Contact () {Log D. ("Test", "Im Year"); Return mockcontacts; }}; Context = moccontax; SetApplication (mockApplication); Prefs = PreferenceManager.getDefaultSharedPreferences (reference); . Prefs.edit () (pronounced) (committed). Super.setUp (); }  

Last night, I ran into this error, try to use " moccontax ".

  Expands the public class AppPreferencesTest instrumentation preferences (AppPreferences preferences); Reference Reference; @ First public set up () throws an exception {context = new MockContext (); Preferences = new AppPreferences (reference); }  

Please see another example here:


No comments:

Post a Comment