View LaunchesScreenRobot.kt
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
internal fun launchesScreenRobot( | |
composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<EntryPointActivity>, EntryPointActivity>, | |
func: LaunchesScreenRobot.() -> Unit | |
) = LaunchesScreenRobot(composeTestRule).also { func } | |
internal open class LaunchesScreenRobot constructor( | |
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<EntryPointActivity>, EntryPointActivity> | |
) { | |
// Robot definitions and functions | |
} |
View LaunchesScreenKtTest.kt
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 elementsVisibilityAfterOpeningTheScreen() { | |
launchesScreenRobot(composeTestRule) { | |
clickOnLaunchesTab() | |
initialElementsShowed() | |
} | |
} | |
@Test | |
fun elementsVisibilityAfterOpeningTheScreen() { |
View LaunchesScreenKtTest.kt
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
@ExperimentalMaterialApi | |
@RunWith(AndroidJUnit4::class) | |
@HiltAndroidTest | |
class LaunchesScreenKtTest : BaseScreenTest() { | |
@Test | |
@InternalCoroutinesApi | |
fun visibleItemsCountAfterOpeningTheScreen() { | |
mockWebServer.dispatcher = SuccessDispatcher() | |
setMainContent() |
View BaseTest.kt
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
val mockWebServer by lazy { MockWebServer() } | |
@Before | |
fun setUp() { | |
mockWebServer.start(BuildConfig.PORT) | |
} | |
@After | |
fun teardown() { | |
mockWebServer.shutdown() |
View NetworkModule.kt
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
@InstallIn(SingletonComponent::class) | |
@Module | |
open class NetworkModule { | |
open fun getBaseUrl () ="https://api.spacexdata.com/v3/" | |
@Provides | |
@BaseUrl | |
fun provideBaseUrl() = getBaseUrl () |
View FakeNetworkModule.kt
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
@Module | |
@TestInstallIn( | |
components = [SingletonComponent::class], | |
replaces = [NetworkModule::class] | |
) | |
class FakeNetworkModule : NetworkModule() { | |
override fun getBaseUrl() = "http://127.0.0.1:${BuildConfig.PORT}" | |
} |
View LaunchesScreenTest.kt
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 | |
@InternalCoroutinesApi | |
fun elementsVisibilityAfterTwoItemsRetrieved() { | |
composeTestRule.apply { | |
setContent { | |
SpaceXTheme { | |
LaunchesScreen( | |
state = LaunchesContract.State( | |
listOf( | |
LaunchUiModel( |
View MockTestRunner.kt
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 MockTestRunner : AndroidJUnitRunner() { | |
override fun onCreate(arguments: Bundle?) { | |
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().permitAll().build()) | |
super.onCreate(arguments) | |
} | |
override fun newApplication( | |
cl: ClassLoader?, | |
className: String?, | |
context: Context? |
View build.gradle.kts
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
android { | |
defaultConfig { | |
applicationId = "prieto.fernando.sample" | |
testInstrumentationRunner = "prieto.fernando.sample.webmock.MockTestRunner" | |
} | |
buildFeatures { | |
compose = true | |
viewBinding = true | |
} | |
// rest of configuration |
View MainScreenTest.kt
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
private val dialogFilterButton by lazy { | |
composeTestRule.onNodeWithContentDescription("Filter Button") | |
} | |
@Test | |
fun elementsVisibilityAfterOpeningTheMainScreen() { | |
setMainContent() | |
dialogFilterButton.assertIsDisplayed() | |
} | |
NewerOlder