android-testing

How to use ActivityTestRule when launching activity with bundle?

半世苍凉 提交于 2020-04-18 07:01:07
问题 I am using val activityRule = ActivityTestRule(SingleFragmentActivity::class.java, true, true) and SingleFragmentActivity is a test helper activity class I used from google GithubBrowseSample how can I launch activity with bundle ? 回答1: You can get activity from activityRule and you can set extra data for intent activityRule.activity.intent.putExtra("key",value) 回答2: There are 2 ways of achieve what you would like to. First one, unfortunately, require creating custom ActivityRule , which will

Fragment testing error: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class <unknown>

早过忘川 提交于 2020-04-17 22:45:49
问题 I am trying to test a fragment, following these instructions: https://developer.android.com/training/basics/fragments/testing However I am getting the following crash when calling launchFragmentInContainer from my test. Stacktrace: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class <unknown> Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown> Caused by: java.lang.reflect

Navigation components - Mocking Navcontroller graph

我只是一个虾纸丫 提交于 2020-04-16 03:47:47
问题 I'm using navigation components and I'm trying to test my Fragment with instrumented test. The fragment has a custom toolbar initialized in onViewCreated method by an extension function. override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) tbBlack.init() } fun androidx.appcompat.widget.Toolbar.init( menuId: Int? = null ) { title = "" menuId?.let { inflateMenu(it) } findNavController().let { it.graph.let { graph -> val

Navigation components - Mocking Navcontroller graph

北城余情 提交于 2020-04-16 03:47:09
问题 I'm using navigation components and I'm trying to test my Fragment with instrumented test. The fragment has a custom toolbar initialized in onViewCreated method by an extension function. override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) tbBlack.init() } fun androidx.appcompat.widget.Toolbar.init( menuId: Int? = null ) { title = "" menuId?.let { inflateMenu(it) } findNavController().let { it.graph.let { graph -> val

Android Studio Mark Directory as Test Sources Root

五迷三道 提交于 2020-04-09 05:00:08
问题 I've done something in build.gradle to remove the green highlighting of the androidTest.java package. I don't know how to get it back. IntelliJ has a "Mark directory as test sources root" option in the context menu but I can't find the equivalent in Android Studio. Is there a way to define this folder so I can start testing? (If it means anything, the test java files all have an icon of a "J" with a red circle around it) 回答1: You can click on the folder and type Cmd + Shift + a to enter the

Android Studio Mark Directory as Test Sources Root

十年热恋 提交于 2020-04-09 04:59:10
问题 I've done something in build.gradle to remove the green highlighting of the androidTest.java package. I don't know how to get it back. IntelliJ has a "Mark directory as test sources root" option in the context menu but I can't find the equivalent in Android Studio. Is there a way to define this folder so I can start testing? (If it means anything, the test java files all have an icon of a "J" with a red circle around it) 回答1: You can click on the folder and type Cmd + Shift + a to enter the

Android Studio Mark Directory as Test Sources Root

故事扮演 提交于 2020-04-09 04:57:08
问题 I've done something in build.gradle to remove the green highlighting of the androidTest.java package. I don't know how to get it back. IntelliJ has a "Mark directory as test sources root" option in the context menu but I can't find the equivalent in Android Studio. Is there a way to define this folder so I can start testing? (If it means anything, the test java files all have an icon of a "J" with a red circle around it) 回答1: You can click on the folder and type Cmd + Shift + a to enter the

Access external files (Outside of AVD device) using Android JUnit

浪尽此生 提交于 2020-02-08 09:58:09
问题 I am using Robotium to automate Android application. Created a android test project for the same. Inside project folder I want to keep some files like .properties/.xls etc. and want to read from /write to those files. For example, I have one config.properties file under my Android test project directory ( src/main/java/config ) and I want to access that file through coding: For normal Java project I used following code snippet to load config.properties file: CONFIG = new Properties();

Clicking on one of many views with same id in Espresso

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-05 13:37:42
问题 I have a layout (A) that includes another layout (B) multiple times. Layout B contains a button with id R.id.my_button . As a result, layout A contains many of those buttons with the same id. How do I test clicking on any of those buttons with espresso? onView(withId(R.id.my_button)).perform(click()); doesn't really do anything in this case. 回答1: Probably, your layout B contains also some unique information, let's say TextView with unique name . In this case your code will look like this:

Android Studio Instrumentation testing build variant

扶醉桌前 提交于 2020-01-29 02:39:50
问题 So I am trying to write instrumentation tests using a custom build variant, mock. In this build variant I mocked up my classes and server. When I try using the mock build myself it works fine, but I can't seem to use my mock build for testing. Here's what my configuration looks like inside Android Studio. I had some issues getting my tests to run so I tried to uninstall all versions of my app except my mock version and I keep getting this error: Test running startedTest running failed: Unable