Skip to content

Instantly share code, notes, and snippets.

View trietbui85's full-sized avatar

trietbui85 trietbui85

  • Zalora
  • HCMC, Vietnam
  • 01:34 (UTC +07:00)
View GitHub Profile
@trietbui85
trietbui85 / test_button_add_clicked.kt
Last active July 29, 2020 13:42
Unit test Android custom view with AndroidX Test and Robolectric
@Test
fun testButtonAddIsClicked() {
countView.reset()
buttonAdd.performClick()
assertThat(countView.countValue).isEqualTo(1)
assertThat(textViewValue.text.toString()).isEqualTo("1")
buttonAdd.performClick()
assertThat(countView.countValue).isEqualTo(2)
@trietbui85
trietbui85 / test_reset_method.kt
Last active July 29, 2020 13:42
Unit test Android custom view with AndroidX Test and Robolectric
@Test
fun testReset() {
countView.reset()
assertThat(countView.countValue).isEqualTo(0)
assertThat(textViewValue.text.toString()).isEqualTo("0")
}
@trietbui85
trietbui85 / test_button_add.kt
Last active July 29, 2020 13:42
Unit test Android custom view with AndroidX Test and Robolectric
@Test
fun testUiOfButtonAdd() {
assertThat(buttonAdd.isEnabled).isTrue()
assertThat(buttonAdd.visibility).isEqualTo(View.VISIBLE)
assertThat(buttonAdd.text).isEqualTo(context.getString(R.string.button_add))
assertThat(buttonAdd.textSize).isEqualTo(context.resources.getDimension(R.dimen.count_text_size))
}
@trietbui85
trietbui85 / setup_test_file.kt
Last active July 29, 2020 13:42
Unit test Android custom view with AndroidX Test and Robolectric
package com.mobtiso.test.customview
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@trietbui85
trietbui85 / CountView.kt
Last active July 29, 2020 13:41
Unit test Android custom view with AndroidX Test and Robolectric
class CountView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
) : LinearLayout(context, attrs, defStyleAttr, defStyleRes) {
private val buttonSubtract: Button
private val buttonAdd: Button
private val textViewCount: TextView
@trietbui85
trietbui85 / count_custom_view.xml
Last active July 29, 2020 13:41
Unit test Android custom view with AndroidX Test and Robolectric
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="10dp"
android:background="#50000000">
<Button
@trietbui85
trietbui85 / build.gradle
Last active July 29, 2020 13:40
Unit test Android custom view with AndroidX Test and Robolectric
android {
defaultConfig {
...
}
testOptions {
unitTests.includeAndroidResources = true
}
}
@trietbui85
trietbui85 / android_values.xml
Last active July 29, 2020 13:41
Unit test Android custom view with AndroidX Test and Robolectric
<string name="count_content">Count: %d</string>
<string name="button_subtract">-</string>
<string name="button_add">+</string>
<string name="button_reset">Reset</string>
<dimen name="count_text_size">30sp</dimen>
<dimen name="button_size">60dp</dimen>
@trietbui85
trietbui85 / blur_multiple_widgets_with_dynamic_region.dart
Last active September 30, 2019 09:15
Blur multiple widgets. The correct Widget tree must be: Stack > [Widget1ToBlur, Widget2ToBlur, …, Positioned > ClipRect > BackdropFilter]
/* Copyright (c) 2019 - Bui Minh Triet - [email protected] - http://fluttervn.com */
double _sigmaX = 0.0; // from 0-10
double _sigmaY = 0.0; // from 0-10
double _opacity = 0.1; // from 0-1.0
double _width = 350;
double _height = 300;
double _blurWidth = _width / 2;
double _blurHeight = _height / 2;
Stack(
@trietbui85
trietbui85 / blur_multiple_widgets.dart
Last active September 30, 2019 07:38
Blur multiple widgets. The correct Widget tree must be: Stack > [Widget1ToBlur, Widget2ToBlur, …, Container > BackdropFilter]
/* Copyright (c) 2019 - Bui Minh Triet - [email protected] - http://fluttervn.com */
double _sigmaX = 0.0; // from 0-10
double _sigmaY = 0.0; // from 0-10
double _opacity = 0.1; // from 0-1.0
double _width = 350;
double _height = 300;
Stack(
children: <Widget>[
Image.asset(