Android Instrumented Unit Test: Print Output Log
October 7, 2019Just use Log.d
.
@RunWith(AndroidJUnit4::class)
class LogTest {
companion object {
private const val TAG = "LogTest"
}
@Test
fun logOutput() {
Log.d(TAG, "Hello")
}
}
Sometimes the Logcat tab is now showing any output, you could try one or more of the following.
- Make sure Logcat tab is selected/active when running the test
Edit Configuration
of theLogTest
: UnderMiscellaneous
checkLogcat -> Clear log before launch
and maybe uncheckInstallation Options -> Skip Installation if APK has not changed
(you can check it again later after logcat is working)- Unplugged the USB cable and plug in again
NOTE: During Instrumented Unit Test run, the package name dropdown in Logcat
tab is usually shown as [DEAD]
, but the log will show despite the [DEAD]
status.
NOTE: System.out.println
used to work in earlier version to print output in the Run
tab, but this is no longer the case with Android Studio 3.5
- algo-trading
- algolia
- analytics
- android
- android-ktx
- android-permission
- android-studio
- apps-script
- bash
- binance
- bootstrap
- bootstrapvue
- chartjs
- chrome
- cloud-functions
- coding-interview
- contentresolver
- coroutines
- crashlytics
- crypto
- css
- dagger2
- datastore
- datetime
- docker
- eslint
- firebase
- firebase-auth
- firebase-hosting
- firestore
- firestore-security-rules
- flask
- fontawesome
- fresco
- git
- github
- glide
- godot
- google-app-engine
- google-cloud-storage
- google-colab
- google-drive
- google-maps
- google-places
- google-play
- google-sheets
- gradle
- html
- hugo
- inkscape
- java
- java-time
- javascript
- jetpack-compose
- jetson-nano
- kotlin
- kotlin-serialization
- layout
- lets-encrypt
- lifecycle
- linux
- logging
- lubuntu
- markdown
- mate
- material-design
- matplotlib
- md5
- mongodb
- moshi
- mplfinance
- mysql
- navigation
- nginx
- nodejs
- npm
- nuxtjs
- nvm
- pandas
- payment
- pip
- pwa
- pyenv
- python
- recylerview
- regex
- room
- rxjava
- scoped-storage
- selenium
- social-media
- ssh
- ssl
- static-site-generator
- static-website-hosting
- sublime-text
- ubuntu
- unit-test
- uwsgi
- viewmodel
- viewpager2
- virtualbox
- vue-chartjs
- vue-cli
- vue-router
- vuejs
- vuelidate
- vuepress
- web-development
- web-hosting
- webpack
- windows
- workmanager
- wsl
- yarn