This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////// Kotlin ////////////////////// | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val t = JavaTest() | |
t.test() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
// Return tree depth in O(d) time. | |
public int computeDepth(TreeNode node) { | |
int d = 0; | |
while (node.left != null) { | |
node = node.left; | |
++d; | |
} | |
return d; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4::class) | |
class CreatePostActivityTest : BaseTest() { | |
@Rule | |
@JvmField | |
var activityTestRule = ActivityTestRule(CreatePostActivity::class.java) | |
@Test | |
fun loging_and_createPost_WithText_Success() { | |
login { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreatePostRobot : BaseRobot() { | |
fun enterPostText(text: String) = | |
postText().typeText(text) | |
fun submitPost() = | |
postImageView().click() | |
fun matchResultText(expectedText: String) = | |
postSubmitResultText().isTextDisplayed(expectedText) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4::class) | |
class CreatePostActivityTest : BaseTest() { | |
@Rule | |
@JvmField | |
var activityTestRule = ActivityTestRule(CreatePostActivity::class.java) | |
@Test | |
fun createPost_WithText_Success() { | |
createPost { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreatePostRobot : BaseRobot() { | |
fun enterPostText(text: String) = | |
postText().typeText(text) | |
fun submitPost() = | |
postButton().click() | |
fun matchResultText(expectedText: String) = | |
postSubmitResultText().isTextDisplayed(expectedText) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseTest { | |
val createPost = robotRunner(CreatePostRobot::class) | |
private fun <T : BaseRobot> robotRunner(cls: KClass<T>) = { func: T.() -> Unit -> | |
cls.createInstance().apply { | |
func() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun ViewInteraction.click(): ViewInteraction = | |
perform(ViewActions.click()) | |
fun ViewInteraction.typeText(text: String): ViewInteraction = | |
perform(ViewActions.typeText(text), ViewActions.closeSoftKeyboard()) | |
fun ViewInteraction.isTextDisplayed(text: String): ViewInteraction = | |
check(ViewAssertions.matches(ViewMatchers.withText(text))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreatePostActivityTest { | |
@Test | |
fun void createPost_WithText_Success() { | |
// Find the edit text and perform typing text action | |
// close the keyboard after text has been entered | |
onView(withId(R.id.post_text)) | |
.perform(ViewActions.typeText("This is a post"),ViewActions.closeSoftKeyboard)) | |
// Find the submit post button and perform a click | |
onView(withId(R.id.post_button)) | |
.perform(ViewActions.click()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun mainActivityTest() { | |
val bottomNavigationItemView = onView( | |
allOf( | |
withId(R.id.navigation_dashboard), withContentDescription("Dashboard"), | |
childAtPosition( | |
childAtPosition( | |
withId(R.id.navigation), | |
0 |
NewerOlder