robolectric

Testing Activity with a Fragment with Robolectric

谁都会走 提交于 2019-12-13 05:19:59
问题 I want to check if the Activity I create in a test is showing a Fragment . How can I do this? I've tried searching through Stack Overflow and Google but I couldn't find anything. 回答1: You need to find the fragment by id with activity.getFragmentManager.findFragmentById(R.id.your_fragment_container); If this returns something different from null , then it means that your container has a Fragment . 来源: https://stackoverflow.com/questions/33811580/testing-activity-with-a-fragment-with

configure Robolectric to write logs (tests output) into external file

大兔子大兔子 提交于 2019-12-13 03:44:29
问题 I'm adding the following code to build.gradle : android{ testOptions { unitTests.all { systemProperty 'robolectric.logging', '/path/to/file/robolectric.log' systemProperty 'robolectric.logging.enabled', 'true' } } } The file /path/to/file/robolectric.log has 777 permissions. The robolectric.logging.enabled=true is working because I started to see the output when I had configured with robolectric.logging=stdout (like here) Questions: 1) How to configure Robolectric to write the output into a

Android unit test Robolectric Maven : The method buildActivity(Class<MyActivity>) is undefined for the type Robolectric

 ̄綄美尐妖づ 提交于 2019-12-13 02:30:09
问题 I am trying to creat some tests for my android application in Maven/Eclipse with Roboelectric. I have an error in the method buildActivity() from the Robolectric class: The method buildActivity(Class<MyActivity>) is undefined for the type Robolectric This is how I am calling it : @Before public void setup() { activity = Robolectric.buildActivity(StartActivity.class).create() .get(); } And this is my dependency in POM.xml : <dependency> <groupId>org.robolectric</groupId> <artifactId

Unit testing with Crosswalk and Robolectric

前提是你 提交于 2019-12-13 01:42:46
问题 We have unit tests running against our app, based on Robolectric. Some of these tests check against activities that contain WebViews. Now we decided to use Crosswalk and, therefore, replace WebView with XWalkView in our layout XML files. But since then, the unit tests fail to run because Robolectric apparently doesn't support XWalkView s yet. We tried writing a shadow for XWalkView, but Robolectric still calls the real implementation when inflating the content view. Other shadows (e.g. a

How to unit test location provider by Robolectric?

我们两清 提交于 2019-12-13 00:25:27
问题 There are a lot of good docs regard unit testing location such as Android - Robolectric - Unit testing request location updates (LocationManager) but unfortunately didn't find anything regard location provider. Since I'm new to Robolectric I still have no clear insight how it works. Any idea would be appreciated. Following code is a method I have in my activity. I display a cardView if this method returns false otherwise it is invisible. So I actually want to test visibility of this view but

Robolectric 3 GooglePlayServicesNotAvailableException

被刻印的时光 ゝ 提交于 2019-12-12 13:21:07
问题 I've just started to use Robolectric and wanted to know how to resolve Google Play Services . I'm using Robolectric 3 RC2 , and my gradle is as follow : build.bradle compile 'com.squareup.okhttp:okhttp:2.3.0' compile 'com.google.android.gms:play-services:7.0.0' testCompile ("org.robolectric:robolectric:3.0-rc2"){ exclude module: 'commons-logging' exclude module: 'httpclient' } testCompile ("org.robolectric:shadows-play-services:3.0-rc2"){ exclude module: 'commons-logging' exclude module:

Using Robolectric with SQLiteAssetHelper

风格不统一 提交于 2019-12-12 13:04:57
问题 I'm very new to Robolectric, so apologies in advance if I'm missing something obvious here. I have an app that loads a database from the assets directory using an SQLiteAssetHelper, and I'd like to test that database using the Robolectric framework. I'm able to get a reference to the database, but it seems to be empty. SQLiteAssetHelper outputs a "successfully opened database" message to the log, but there are no tables in the database. Edit: Here's the code I'm using to get the database in

DialogFragment with Roboelctric

时光毁灭记忆、已成空白 提交于 2019-12-12 11:27:36
问题 I wanted to test if a dialog Fragment is shown or not, with Roboelectric . public class SomeDialogActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); DialogFragment someDialogFragment = new SomeDialogFragment(); someDialogFragment.show(getSupportFragmentManager(), "some_dialog"); } } Now I wanted to test if this dialog is shown, something like this: @Test public void

Configuration change using Robolectric

限于喜欢 提交于 2019-12-12 11:07:30
问题 To retain my AsyncTasks across configuration changes, I use a fragment-based solution with setRetainInstance(true), which hosts each AsyncTask and calls back to a listening Activity, similar to this solution http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html Ultimately, the purpose is to test the AsyncTask's retention functionality throughout configuration changes using Robolectric, but I need to start with setting up the actual configuration change

Roboelectric is giving me a java.lang.IllegalArgumentException: INTERNET permission is required

那年仲夏 提交于 2019-12-12 09:44:32
问题 I am retrofitting UnitTests to an existing app. When I run this simple unit test import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.annotation.Config; import static junit.framework.Assert.assertTrue; @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, packageName = "com.blah.blah" ) public class TestThis { @Test public void blah(){ assertTrue(true); } } I get this error java.lang