android-testing

How can I specify android Instrumentation context when I run my ActivityTestRule test cases?

不问归期 提交于 2019-12-24 22:25:26
问题 I have one android system with two displays(Display1, display2) connected for my app. my app has an activity that is running on display2. I was trying to use android espresso library to test my activity on display2. Below is my test code: onView(withId(R.id.button_test)).check(matches(isDisplayed())); //This line worked fine, it means espresso found my view successfully. onView(withId(R.id.button_test)).withFailureHandler(new FailureHandler() { @Override public void handle(Throwable error,

Espresso Webview select hidden element

我是研究僧i 提交于 2019-12-24 17:00:35
问题 How do you find a hidden element inside an Android Webview using espresso? This is what I tried: onWebView().withElement(findElement(Locator.CSS_SELECTOR, "#clsp:hidden")); That produces the following stacktrace. java.lang.RuntimeException: java.lang.RuntimeException: Error in evaluationEvaluation: status: 13 value: {message=An invalid or illegal selector was specified} hasMessage: true message: An invalid or illegal selector was specified at android.support.test.espresso.web.sugar.Web

Android Tests Exception in Constructor NoClassDefFoundError

不羁的心 提交于 2019-12-24 15:12:49
问题 After solving my issues with project structure and android tests it appears that another issue is coming, when I try to run my tests i get this exception: junit.framework.AssertionFailedError: Exception in constructor: testRegisterNaming (java.lang.NoClassDefFoundError: es.unizar.vv.mobile.catmdedit.app.view.LibraryActivity at es.unizar.vv.mobile.catmdedit.app.LibraryTest.<init>(LibraryTest.java:16) at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect

Android Roboelectric 3.0 testing next activity –choosing from multiple activities

╄→尐↘猪︶ㄣ 提交于 2019-12-24 15:00:47
问题 I have scenario like this:-- I have three activities ActivityA(launcher activity), ActivityB, ActivityC Now in Activity A I read the Application context to decide whether to start ActivityB or ActivityC. But even after setting the context value manual, the ActivityA is not updated and second test case fails. Any helps? private ActivityA activityA; private ShadowActivity shadowActivity; @Before public void setUp() { activityA = Robolectric.setupActivity(ActivityA.class); assertNotNull(

Android Integration test application permissions

馋奶兔 提交于 2019-12-24 10:45:31
问题 I'm looking a way to get current device's serial number in my integration tests. Now, when calling TelephonyManager manager = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); String deviceId = manager.getDeviceId(); in my test method, I get java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10227 nor current process has android.permission.READ_PHONE_STATE. I added <uses-permission android:name="android.permission.READ_PHONE_STATE"/> in my test

Can't add JUnit to test and androidTest

a 夏天 提交于 2019-12-24 09:59:52
问题 I need JUnit in both test folders. So I added androidTestCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12' But as soon as I add JUnit to the androidTest I cannot run the tests, because of the error thrownin this log. Any ideas on how to fix this problem? EDIT: I removed the gradle-aware build from the run configuration. Now it says that my TestSuite is empty, but there are tests annotated with @Test 回答1: Hava a try with this in your build.gradle file dependencies { androidTestCompile(

Android ActivityInstrumentationTestCase2 NullPointerException on getting context

亡梦爱人 提交于 2019-12-24 07:02:14
问题 I have an ActivityInstrumentationTestCase2 and I have had no luck getting context for the test. package com.vsnetworks.vsnmedia.test; import org.json.JSONObject; import android.app.Activity; import android.content.Context; import android.test.ActivityInstrumentationTestCase2; import com.vsnetworks.vsnmedia.MainActivity; import com.vsnetworks.vsnmedia.VSWebViewClient; public class TestMimeTypes extends ActivityInstrumentationTestCase2<MainActivity> { Activity activity; Context context; public

Android ActivityInstrumentationTestCase2 NullPointerException on getting context

你说的曾经没有我的故事 提交于 2019-12-24 07:02:06
问题 I have an ActivityInstrumentationTestCase2 and I have had no luck getting context for the test. package com.vsnetworks.vsnmedia.test; import org.json.JSONObject; import android.app.Activity; import android.content.Context; import android.test.ActivityInstrumentationTestCase2; import com.vsnetworks.vsnmedia.MainActivity; import com.vsnetworks.vsnmedia.VSWebViewClient; public class TestMimeTypes extends ActivityInstrumentationTestCase2<MainActivity> { Activity activity; Context context; public

Create unit tests in android studio

和自甴很熟 提交于 2019-12-24 06:46:28
问题 I'm following this tutorial. What I want to do is to create unit tests with AndroidJunitRunner . My directory in app/src looks like this: androidTest debug main release android docs suggests that I create a test/java for my unit tests. The problem is that in android studio I can't create a new directory if I'm on android project mode. And I should find the directory manually and create it manually. Is there a way to automatically create these directories and tests for one flavor? I've read

Android command line - how to run a single unit test method

可紊 提交于 2019-12-24 06:30:05
问题 in android from command line i am trying to run just a single test case. from the IDE it works fine by right click. But when i try to do it using the following command in CLI IT FAILS: ./gradlew test --tests "com.xyz.b.module.TestClass.testToRun" i get the following error: > Unknown command-line option '--tests'. i guess its a old thread perhaps but i was following here: Anyway , how can i run my UNIT TEST single method ? i want to emphasis that i want to run a single unit test not