Skip to content

Commit

Permalink
[JetNews] Removes sharedTest trick and Robolectric (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAlcerreca authored Sep 23, 2024
2 parents 4e2918a + 16514f4 commit d5b5ec0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 38 deletions.
24 changes: 0 additions & 24 deletions JetNews/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,6 @@ android {
}
}

testOptions {
unitTests {
isReturnDefaultValues = true
isIncludeAndroidResources = true
}
}

// Tests can be Robolectric or instrumented tests
sourceSets {
val sharedTestDir = "src/sharedTest/java"
getByName("test") {
java.srcDir(sharedTestDir)
}
getByName("androidTest") {
java.srcDir(sharedTestDir)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -146,11 +128,5 @@ dependencies {
androidTestImplementation(libs.kotlinx.coroutines.test)
androidTestImplementation(libs.androidx.compose.ui.test)
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
// Robolectric dependencies
testImplementation(libs.androidx.compose.ui.test.junit4)
testImplementation(libs.robolectric)
}

tasks.withType<Test>().configureEach {
systemProperties.put("robolectric.logging", "stdout")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@

package com.example.jetnews

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.printToString
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.jetnews.data.posts.impl.manuel
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalTestApi::class)
@RunWith(AndroidJUnit4::class)
class JetnewsTests {

@get:Rule
val composeTestRule = createComposeRule()
val composeTestRule = createAndroidComposeRule<ComponentActivity>()

@Before
fun setUp() {
Expand All @@ -44,14 +48,16 @@ class JetnewsTests {

@Test
fun app_launches() {
composeTestRule.onNodeWithText("Top stories for you").assertExists()
composeTestRule
.onNodeWithText(composeTestRule.activity.getString(R.string.home_top_section_title))
.assertExists()
}

@Test
fun app_opensArticle() {

println(composeTestRule.onRoot().printToString())
composeTestRule.onAllNodes(hasText("Manuel Vivo", substring = true))[0].performClick()
composeTestRule.onAllNodes(hasText(manuel.name, substring = true))[0].performClick()

println(composeTestRule.onRoot().printToString())
try {
Expand All @@ -69,7 +75,6 @@ class JetnewsTests {
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText("Interests").performClick()
// TODO - this fails on CI but not locally. (https://github.com/android/compose-samples/issues/1442)
// composeTestRule.waitUntilAtLeastOneExists(hasText("Topics"), 5000L)
composeTestRule.waitUntilAtLeastOneExists(hasText("Topics"), 5000L)
}
}
8 changes: 0 additions & 8 deletions JetNews/app/src/test/resources/robolectric.properties

This file was deleted.

0 comments on commit d5b5ec0

Please sign in to comment.