Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myunittest.ui
- import com.example.myunittest.R
- import androidx.test.core.app.ActivityScenario
- import androidx.test.espresso.*
- import androidx.test.espresso.Espresso.*
- import androidx.test.espresso.action.*
- import androidx.test.espresso.action.ViewActions.*
- import androidx.test.espresso.matcher.ViewMatchers.*
- import androidx.test.espresso.assertion.ViewAssertions.*
- import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
- import org.junit.Assert.*
- import org.junit.*
- import org.junit.runner.*
- @RunWith(AndroidJUnit4ClassRunner::class)
- class MainActivityTest {
- private val dummyVolume = "504.0"
- private val dummyCircumference = "100.0"
- private val dummySurfaceArea = "396.0"
- private val dummyLength = "12.0"
- private val dummyWidth = "7.0"
- private val dummyHeight = "6.0"
- private val emptyInput = ""
- private val fieldEmpty = "Field ini tidak boleh kosong"
- @Before
- fun setup(){
- ActivityScenario.launch(MainActivity::class.java)
- }
- @Test
- fun assertGetCircumference() {
- onView(withId(R.id.edt_length)).perform(typeText(dummyLength), closeSoftKeyboard())
- onView(withId(R.id.edt_width)).perform(typeText(dummyWidth), closeSoftKeyboard())
- onView(withId(R.id.edt_height)).perform(typeText(dummyHeight), closeSoftKeyboard())
- onView(withId(R.id.btn_save)).check(matches(isDisplayed()))
- onView(withId(R.id.btn_save)).perform(click())
- onView(withId(R.id.btn_calculate_circumference)).check(matches(isDisplayed()))
- onView(withId(R.id.btn_calculate_circumference)).perform(click())
- onView(withId(R.id.tv_result)).check(matches(isDisplayed()))
- onView(withId(R.id.tv_result)).check(matches(withText(dummyCircumference)))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement