robolectric

Class loading collision between Robolectric and Powermock

青春壹個敷衍的年華 提交于 2019-12-12 08:53:54
问题 I'm trying to write a test that needs both Robolectric 2.2 and PowerMock , as the code under test depends on some Android libraries and third party libraries with final classes that I need to mock. Given that I'm forced to use the Robolectric test runner through: @RunWith(RobolectricTestRunner.class) ...I cannot use the PowerMock test runner, so I'm trying to go with the PowerMock java agent alternative, without luck so far. I have setup everything according to this guide but I'm facing a

How do you force a configuration change in an Android Robolectric test?

一个人想着一个人 提交于 2019-12-12 08:18:27
问题 I'm using robolectric to make my android unit tests fast enough to be useful. I want to test that code I've written works while the screen orientation is changing to simulate a common real world use case. Specifically what I'm testing is an asynchronous http call to a server with some xml parsed after the result is fetched. I have the unit test for all that working great but can't figure out how to simulate the screen rotation. Any state change that causes the activity to recreate itself is

osx maven running tests Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread “main”

﹥>﹥吖頭↗ 提交于 2019-12-12 07:50:08
问题 I have been trying to run on mac a ready maven project which works under linux. When calling mvn clean install it runs a portion of the tests and then I am getting the following error: Exception in thread "main" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main" I have seen many questions about Perm gen error fixed with adding MAVEN_OPTS to environmental variables. Right now I have the following environmental variable on my system: MAVEN_OPTS="

Android Testing Handler.postDelayed

北慕城南 提交于 2019-12-12 07:14:55
问题 I'm newbie on Android and get stuck on testing a SplashScreen, basically what I'm doing is trying to test that the splash screen stays on for 3s. this is the code for the splashScreen @Override protected void onStart() { super.onStart(); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(SplashScreenActivity.this, MainActivity.class); startActivity(i); finish(); } }, SPLASH_TIME_OUT); } And this is my approach for the test: @Test public void

Android robolectric tests manifest merge issue (android beacon library)

允我心安 提交于 2019-12-12 05:38:50
问题 I have the simple Test Case @Config(constants = BuildConfig.class) @RunWith(RobolectricGradleTestRunner.class) public class BaseTest { @Test public void startEverTestSugarAppAsFirst() { BeaconManager.setsManifestCheckingDisabled(true); } } Unfortunately the runner hits manifestmerger issue java.lang.RuntimeException: org.altbeacon.beacon.BeaconManager$ServiceNotDeclaredException: The BeaconService is not properly declared in AndroidManifest.xml. If using Eclipse, please verify that your

Can't run android test suite: Exception in thread “main” java.lang.ClassNotFoundException

若如初见. 提交于 2019-12-11 23:19:12
问题 I have 2 test classes that I need to run on a test suite one is RestaurantModelTest the other is CartModelTest.class : @Config(sdk = 16, manifest = "src/main/AndroidManifest.xml") @RunWith(RobolectricTestRunner.class) public class RestaurantModelTest { //setUp code here... @Test public void testFindByLocation() throws Exception { //test code here } } So I followed some tutorials online and they specify to create a TestSuite class like this with my 2 classes to be tested: import org.junit

In Robolectric test, how to wait for messages in the main looper to be run?

坚强是说给别人听的谎言 提交于 2019-12-11 20:33:05
问题 I'm testing a Service using Robolectric 3. Once run, it registers an anonymous BroadcastReceive waits for the system to send a broadcast after some event occurred. In the test I initialize the service so that it registers the BroadcastReceiver, then I trigger the system event, then I verify that the service state changed accordingly after the broadcast is handled. But because the onReceive method is run asynchronously, the assertions are run too soon. But using Thread.sleep in the test didn't

java.lang.NoSuchMethodException with JMockit 1.5 and Robolectric 2.2

老子叫甜甜 提交于 2019-12-11 18:12:32
问题 I'm trying to use JMockit 1.5 with robolectric 2.2 but I get a java.lang.NoSuchMethodException as soon I try to create an Activity. I've reduced the test to this: @RunWith(RobolectricTestRunner.class) //@RunWith(MyTestRunner.class) public class Test_login { @Test public void test_login(@Mocked final Intent in) { FragmentActivity frag = Robolectric.buildActivity(MainActivity.class).create().get(); } } But I get this stack trace: java.lang.RuntimeException: java.lang.NoSuchMethodException: org

Robolectric 3 with Fabric Crashlytics

☆樱花仙子☆ 提交于 2019-12-11 14:24:22
问题 I am trying to ShadowClass Crashlytics/Fabric so that Robotlectric 3 tests do not fail. What I have so far is this: The custom test runner that adds the Shadow class for Fabric: public class TestRunner extends RobolectricGradleTestRunner { public TestRunner(Class<?> klass) throws InitializationError { super(klass); } @Override protected ShadowMap createShadowMap() { return super.createShadowMap() .newBuilder().addShadowClass(ShadowFabric.class).build(); } @Override public

Attempting to check Settings.System.canWrite(context) result

让人想犯罪 __ 提交于 2019-12-11 13:43:04
问题 I'm using Robolectric 3.5 and the latest from Android Studio 3.0 , and I'm attempting a piece of code, which needs to verify Settings.System.canWrite(Context context) was called and also do something with the true / false result. I've been checking around, and I cannot figure out how to set up this scenario with Robolectric. How do you approach it? //the settings write verifier class... ... public SettingsWriteVerifier(ctxt){ context = ctxt; } public boolean canWrite() { return Settings