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 BaseMainActivityTest { | |
@get:Rule | |
var activityRule = ActivityTestRule(MainActivity::class.java) | |
protected val context: Context by lazy { activityRule.activity } | |
// test goes here just like this example from Espresso documentation | |
} |
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 BaseMainActivityTest { | |
@get:Rule | |
var activityRule = ActivityTestRule(MainActivity::class.java) | |
@Test | |
fun acitivityIsRunning() { | |
if (true) while(true) Thread.sleep(100); /*DEBUG*/ | |
} |
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 BaseMainActivityTest { | |
@get:Rule | |
var activityRule = ActivityTestRule(MainActivity::class.java) | |
// the context is often needed in more complex Espresso tests | |
protected val context: Context by lazy { activityRule.activity } | |
@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
// try-fail-catch approach | |
try { | |
doMainAction() | |
} catch (exc: SomePreconditionViolated) { | |
doFallbackAction() | |
} | |
/* ^ COMPARE v */ | |
// check-and-execute approach |
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
// try-ignore approach | |
try { | |
doAction() | |
} catch (exc: SomePreconditionViolated) { | |
//ignore | |
} finally { | |
finalize() | |
} | |
/* ^ COMPARE v */ |
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 SomeStrictActivity : Activity() { | |
companion object { | |
@JvmStatic | |
fun createIntent(context: Context, importantParameter: Parameter): Intent { | |
val intent = Intent(context, SomeStrictActivity::class.java) | |
intent.putExtra(EXTRA_PARAMETER, importantParameter) | |
return intent | |
} | |
} |
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
data class SomeData( | |
val intValue: Int, | |
val strValue: String = "default value" | |
) |
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
data class SomeData( | |
val intValue: Int = 0, | |
val strValue: String = "default value" | |
) |
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
data class WithoutDefaultConstructor( | |
val intValue: Int, | |
val strValue: String = "default" | |
) | |
data class WithDefaultConstructor( | |
val intValue: Int = 1, | |
val strValue: String = "default" | |
) |
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
public final class WithoutDefaultConstructor { | |
private final int intValue; | |
@NotNull | |
private final String strValue; | |
public WithoutDefaultConstructor(int intValue, @NotNull String strValue) { | |
super(); | |
this.intValue = intValue; | |
this.strValue = strValue; | |
} |
OlderNewer