android-instrumentation

Use Mockito-core for create mock of final class?

て烟熏妆下的殇ゞ 提交于 2019-12-12 16:14:50
问题 I find in github example how with standart Mockito make instance of final class (BluetoothGatt.class) : ... @RunWith(RobolectricTestRunner.class) @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public class OnBoardingServiceTest { private BluetoothGattCharacteristic characteristic; private OnBoardingService service; private BluetoothGattReceiver receiver = new BluetoothGattReceiver(); @Before public void initialise() { BleDevice bleDevice = mock(BleDevice.class); when(bleDevice.getType())

Android instrumented unit testing Cannot resolve symbol 'AndroidJUnit4'

不打扰是莪最后的温柔 提交于 2019-12-12 11:48:51
问题 I trying to add Android Support Instrumentation test to my application, but i run this problem: Cannot resolve symbol 'AndroidJUnit4' Its seems i don't have the package android.support.test.runner my app's build.gradle: apply plugin: 'com.android.application' apply plugin: 'realm-android' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "---PACKAGENAME---" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" testInstrumentationRunner

Cannot resolve symbol AndroidJUnit4

我是研究僧i 提交于 2019-12-12 10:35:31
问题 I'm trying to add loginfacebook for my app. But when I added a repository that is need in doing this. It caused an error. The AndroidJUnit4 cannot resolve now. ExampleInstrumentedTest.java package com.example.user.enyatravelbataan; import android.content.Context; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import static junit.framework.Assert.assertEquals; import static org.junit

Using Junit to test writing and reading to SQLite

旧城冷巷雨未停 提交于 2019-12-11 20:43:08
问题 I have a dbManager as follows: //TABLE_AUTH Column names public static final String AUTH_CODE = "AuthCode"; public static final String SESSION_ID = "SessionId"; public static final String AUTH_TIME = "LastAuthorized"; public static final String ENCRYPT_KEY = "EncryptKey"; //TABLE_AUTH Create Statement public static final String CREATE_AUTH_TABLE = "CREATE TABLE " + TABLE_AUTH + "(" + AUTH_CODE + " TEXT, " + SESSION_ID + " TEXT, " + AUTH_TIME + " DATETIME, " + ENCRYPT_KEY +" TEXT" +")"; public

UiDevice class missing from UIAutomator 2.1.2

淺唱寂寞╮ 提交于 2019-12-11 15:15:20
问题 I found that "upgrading" my reference to UIAutomator in build.gradle to 2.1.2 broke any references I had to the UiDevice class. In fact, a lot seems to have changed but I'm finding nothing explaining it. Can anyone shed some light on what is (apparently) about to change? This works: androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1' This does not: androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2' Dependencies from build.gradle follow

How make mock of final class?

落花浮王杯 提交于 2019-12-11 08:21:37
问题 Work in AndroidStudio. Want make mock of final class for AndroidInstrumentalTest with PowerMock. Added libs in gradle: androidTestCompile ('org.powermock:powermock-api-mockito:1.5.6') androidTestCompile ('org.powermock:powermock-core:1.5.6') androidTestCompile ('org.powermock:powermock-module-junit4:1.5.6') androidTestCompile 'org.mockito:mockito-core:1.10.8' androidTestCompile 'com.google.dexmaker:dexmaker:1.1' androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.1' Make test class:

How can I swap test doubles at the scope of an Activity or a Fragment using Dagger 2?

岁酱吖の 提交于 2019-12-11 06:45:26
问题 EDIT: Watch out! I have deleted the old repository reffered to in this question. See my own answer to the question for a possible solution and feel free to improve it! I am refering to my post here. Now I came a little further. I am also refering to my two branches within my github Project: Experimental [branch no. 1] (repository deleted) Experimental [branch no. 2] (repository deleted) In the old post I tried to swap components to test-components within an Instrumentation Test. This works

How to register broadcast receiver inside instrumentation?

纵饮孤独 提交于 2019-12-11 06:38:26
问题 I am trying to get bluetooth discovery results through an apk which runs as android junit runner. Everything works fine but while registerReciever I get below error. What could be the reason ? java.lang.SecurityException: Given caller package com.ex.test is not running in process ProcessRecord{d740580 19462:com.ex/u0a302} Code- @Test public void demo() throws Exception { Context ctx = InstrumentationRegistry.getInstrumentation().getContext(); BluetoothAdapter mBtAdapter = BluetoothAdapter

Androidx ServiceTestRule cannot find my service

烂漫一生 提交于 2019-12-11 05:39:31
问题 To be fair, I am not testing the service, but am using a service as part of my test classes to test a Bluetooth library. So my test class needs to create a service that invokes the Bluetooth library. The test class then needs to bind to this service to perform the tests. However, attempting to start the service always gives me the following error which leads to a Nullpointer exception W/ActivityManager: Unable to start service Intent { cmp=com.example.androidhdpadapter.test/com

How to use PowerMock on android sdk

…衆ロ難τιáo~ 提交于 2019-12-11 02:44:43
问题 I want to write some unit tests and instrumentation tests for my android project. However, I've met a problem that stuck me a while... I need to mock a static method and fake the return value to test the project. After survey from some forums, the only way to do this is to use PowerMock to mock the static method. This is a part of my gradle: androidTestCompile "org.powermock:powermock-module-junit4:1.7.0" androidTestCompile "org.powermock:powermock-module-junit4-rule:1.7.0" androidTestCompile