robolectric

How to access files from assets folder during tests execution?

谁都会走 提交于 2019-12-03 05:50:59
问题 How to access files from assets folder during unit tests execution? My project is build using Gradle, I use Robolectric to run tests. It seems like gradle is being recognizing the assets : This is how I'm struggling to read the file: public String readFileFromAssets(String fileName) throws IOException { InputStream stream = getClass().getClassLoader().getResourceAsStream("assets/" + fileName); Preconditions.checkNotNull(stream, "Stream is null"); BufferedReader reader = new BufferedReader(new

Where is log output written to when using Robolectric + Roboguice?

五迷三道 提交于 2019-12-03 05:25:38
问题 I'm using Robolectric to test Android. I'm running my tests via maven, e.g. mvn -Dtest=LogTest test If I have code that writes to the logs, such as Log.d("TAG", "blah"); or using Roboguice's Ln Ln.d("blah"); I don't see any output in maven's surefire logs (text files). Ideally, I actually want simple log statements to go to the console. I can write to the console by using System.out.println("blah") , but of course I'd rather use the supported logging APIs. So my question is, why am I not

kotlin and ArgumentCaptor - IllegalStateException

耗尽温柔 提交于 2019-12-03 04:16:19
I have a problem with capturing the Class argument via ArgumentCaptor. My test class looks like this: @RunWith(RobolectricGradleTestRunner::class) @Config(sdk = intArrayOf(21), constants = BuildConfig::class) class MyViewModelTest { @Mock lateinit var activityHandlerMock: IActivityHandler; @Captor lateinit var classCaptor: ArgumentCaptor<Class<BaseActivity>> @Captor lateinit var booleanCaptor: ArgumentCaptor<Boolean> private var objectUnderTest: MyViewModel? = null @Before fun setUp() { initMocks(this) ... objectUnderTest = MyViewModel(...) } @Test fun thatNavigatesToAddListScreenOnAddClicked(

Unable to locate a Java Runtime Android Studio Robolectric

我们两清 提交于 2019-12-03 04:14:42
问题 I've added Robolectric to an Android project. I'm using Android Studio with Build Tools in 19.0.1. I can run the tests with: $./gradlew test Which execute fine. If I try: $ gradle installDebug It executes fine as well: $ ./gradlew installDebug WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for debugTest as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages WARNING:

Robolectric not using test application

旧时模样 提交于 2019-12-03 03:51:31
According to this link I can create a test application which Robolectric will automatically start using in tests. I cannot get this to work. I am using Dagger for dependency injection and have created injection wrapper classes for Activity and Application . Then each of my activities extends the wrapper activity class instead of plain old Activity . The problem I am having is that, in tests, the dependencies provided by the Application modules can't be resolved and so the tests fail. This is because most of our tests are just building an activity (using Robolectric.buildActivity() ) and aren't

Testing ViewPager (and CursorLoader) with Robolectric

谁说胖子不能爱 提交于 2019-12-03 03:23:18
问题 Does anyone know how to test the following setup using Robolectric? Fragment containing a ViewPager, data loaded with a CursorLoader. With the code below, the CursorLoader is never pushed into the adapter for the view pager. I get stuck at the await() call. EventsFragmentTest.java: @RunWith(CustomRobolectricTestRunner.class) public class EventsFragmentTest extends AbstractDbAndUiDriver { // which element in the view pager we are testing private static final int TEST_INDEX = 0; protected

Android Lollipop Appcompat problems running with Robolectric

笑着哭i 提交于 2019-12-03 03:16:49
I'm not able to run Robolectic test when using new Appcompat support library available since Android Lollipop came out. I've followed: https://github.com/robolectric/deckard-gradle https://chris.banes.me/2014/10/17/appcompat-v21/ My current progress is available here: https://github.com/fada21/android-tdd-bootstrap My configuration (distilled) is: android { compileSdkVersion 21 buildToolsVersion "21.0.1" defaultConfig { applicationId "com.fada21.android.bootstrap" minSdkVersion 15 targetSdkVersion 21 ... dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android

Getting Robolectric to work with Volley

血红的双手。 提交于 2019-12-03 02:00:50
I am trying to get Volley working with Robolectric. I can see that my HTTP request is getting called, and parseNetworkResponse is getting called (I'm sending a custom subclass of JsonRequest), but my Listener is NOT getting called. Any advice? Here is a code sample: @Test public void testTypeAheadClient() throws Exception { Robolectric.getFakeHttpLayer().interceptHttpRequests(false); //mRemoteRequestQueue and mCustomRequest are set up previously mRemoteRequestQueue.add(mCustomRequest); } private static class CustomRequest extends JsonRequest<MyObject> { public CustomRequest(String url,

Android unit test case automation: Robolectric library vs Android Testing framework

懵懂的女人 提交于 2019-12-03 01:28:40
问题 Wondering which one is the better choice to write unit test cases for android apps and libraries: Using Robolectric library or sticking with Android Testing framework. I want to run test suite at commandline and want it be independent of need of configuring emulator or letting a device attached with build machine. Does anyone of you run a comparative analysis on both of these or something better? Your experiences will be great help me to decide on the better solution. 回答1: I use a tiered

Robolectric unit tests fail after Multidex

橙三吉。 提交于 2019-12-02 21:41:12
So I recently merged my robolectric 3.0 upgrade with our mainline, which had added multidex support to our application. Unfortunately, this had the unfortunate side effect of causing our tests to fail/not run - they'd simply stop after the first failed attempt to install MultiDex, with this stack trace: java.lang.RuntimeException: java.lang.RuntimeException: Multi dex installation failed (/Users/me/Data/Projects/my-android/myapp/. (Is a directory)). at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:257) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java