-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from PetJournal/cicdtest
Cicdtest
- Loading branch information
Showing
25 changed files
with
867 additions
and
445 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
name: PetJournalAndroid | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
|
||
jobs: | ||
lint: | ||
name: Static Code Analysis | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the code | ||
uses: actions/[email protected] | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/[email protected] | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: 'gradle' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
working-directory: petJournal | ||
|
||
- name: Run lint | ||
run: ./gradlew lintDebug | ||
working-directory: petJournal | ||
|
||
- name: Upload lint report | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: lint-results-debug.html | ||
path: petJournal/app/build/reports/lint-results-debug.html | ||
|
||
unit-test: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
needs: lint | ||
steps: | ||
- name: Checkout the code | ||
uses: actions/[email protected] | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/[email protected] | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: 'gradle' | ||
|
||
- name: Setup Android SDK | ||
uses: android-actions/setup-android@v3 | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
working-directory: petJournal | ||
|
||
- name: Cache Gradle dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.gradle | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('petJournal/**/*') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
env: | ||
JAVA_HOME: /opt/hostedtoolcache/Java_1.8.0 | ||
|
||
- name: Run unit tests | ||
run: ./gradlew test | ||
working-directory: petJournal | ||
|
||
- name: Upload unit tests report | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: unit_test_report | ||
path: petJournal/app/build/reports/tests/testDebugUnitTest/ | ||
|
||
|
||
# package: | ||
# name: Generate Android App Bundle | ||
# runs-on: ubuntu-latest | ||
# needs: unit-test | ||
# steps: | ||
# - name: Checkout the code | ||
# uses: actions/[email protected] | ||
# | ||
# - name: Set up JDK 17 | ||
# uses: actions/[email protected] | ||
# with: | ||
# java-version: '17' | ||
# distribution: 'temurin' | ||
# cache: 'gradle' | ||
# | ||
# - name: Grant execute permission for gradlew | ||
# run: chmod +x gradlew | ||
# working-directory: petJournal | ||
# | ||
# - name: Build Android App Bundle | ||
# run: ./gradlew bundle | ||
# working-directory: petJournal | ||
# | ||
# - name: Upload Android App Bundle | ||
# uses: actions/upload-artifact@v4 | ||
# with: | ||
# name: app-release.aab | ||
# path: petJournal/app/build/outputs/bundle/release/app-release.aab |
38 changes: 19 additions & 19 deletions
38
petJournal/app/src/androidTest/java/com/soujunior/petjournal/ExampleInstrumentedTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package com.soujunior.petjournal | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.soujunior.petjournal", appContext.packageName) | ||
} | ||
} | ||
//package com.soujunior.petjournal | ||
// | ||
//import androidx.test.platform.app.InstrumentationRegistry | ||
//import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
// | ||
//import org.junit.Test | ||
//import org.junit.runner.RunWith | ||
// | ||
//import org.junit.Assert.* | ||
// | ||
//@RunWith(AndroidJUnit4::class) | ||
//class ExampleInstrumentedTest { | ||
// @Test | ||
// fun useAppContext() { | ||
// // Context of the app under test. | ||
// val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
// assertEquals("com.soujunior.petjournal", appContext.packageName) | ||
// } | ||
//} |
144 changes: 144 additions & 0 deletions
144
.../androidTest/java/com/soujunior/petjournal/nameGenderScreen/NameGenderInstrumentedTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package com.soujunior.petjournal.nameGenderScreen | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.test.assertIsEnabled | ||
import androidx.compose.ui.test.assertIsNotEnabled | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.onRoot | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTextInput | ||
import androidx.compose.ui.test.printToLog | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.soujunior.petjournal.ui.appArea.pets.petNameAndGenderScreen.components.GenderSelector | ||
import com.soujunior.petjournal.ui.components.Button3 | ||
import com.soujunior.petjournal.ui.components.DashedInputText | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class NameGenderInstrumentedTest { | ||
|
||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun textInput_should_return_error(){ | ||
val name = "a" | ||
val nameError = listOf("Adicione um nome entre 2 a 30 caracteres") | ||
composeTestRule.setContent { | ||
DashedInputText( | ||
textValue = name, | ||
textError = nameError, | ||
onEvent = {}, | ||
isError = true | ||
) | ||
} | ||
composeTestRule.onNodeWithText("Adicione um nome entre 2 a 30 caracteres").assertExists() | ||
} | ||
|
||
@Test | ||
fun textInput_should_accept_text(){ | ||
val name = "B0linha" | ||
|
||
composeTestRule.setContent { | ||
DashedInputText( | ||
textValue = name, | ||
onEvent = {}, | ||
isError = false, | ||
) | ||
} | ||
composeTestRule.onNodeWithTag("dashedInputField_test").performTextInput(name) | ||
} | ||
@Test | ||
fun testButtonWithCustomTag() { | ||
composeTestRule.setContent { | ||
Button3( | ||
submit = { /*TODO*/ }, | ||
enableButton = false) | ||
} | ||
|
||
|
||
// Tenta encontrar o botão com a tag "button_test" | ||
composeTestRule.onNodeWithTag("button3_test").assertExists() | ||
} | ||
|
||
@Test | ||
fun genderButtons_should_not_be_empty(){ | ||
val error = listOf("*Campo Obrigatorio") | ||
|
||
composeTestRule.setContent { | ||
GenderSelector( | ||
selectedGender = {}, | ||
clearSelection = {true}, | ||
error) | ||
} | ||
composeTestRule.onNodeWithText(error.toString()) | ||
} | ||
@Test | ||
fun nextButton_should_deactivate_when_inputText_and_GenderButtons_areEmpty(){ | ||
val name = "a" | ||
val errorGender = listOf("*Campo Obrigatorio") | ||
val nameError = listOf("Adicione um nome entre 2 a 30 caracteres") | ||
|
||
composeTestRule.setContent { | ||
DashedInputText( | ||
textValue = name, | ||
textError = nameError, | ||
onEvent = {}, | ||
isError = true | ||
) | ||
|
||
GenderSelector( | ||
selectedGender = {}, | ||
clearSelection = {true}, | ||
errorGender | ||
) | ||
|
||
Button3( | ||
submit = { /*TODO*/ }, | ||
enableButton = false, // Define o botão como desativado | ||
) | ||
} | ||
|
||
composeTestRule.onNodeWithText("Adicione um nome entre 2 a 30 caracteres").assertExists() | ||
composeTestRule.onNodeWithText(errorGender.toString()) | ||
|
||
composeTestRule.onNodeWithTag("button3_test").assertIsNotEnabled() | ||
|
||
|
||
} | ||
@Test | ||
fun enable_nextButton_when_both_fields_are_not_empty(){ | ||
val name = "Bolinha" | ||
|
||
composeTestRule.setContent { | ||
DashedInputText( | ||
textValue = name, | ||
onEvent = {}, | ||
isError = false | ||
) | ||
|
||
GenderSelector( | ||
selectedGender = {"M"}, | ||
clearSelection = {false}, | ||
) | ||
Button3( | ||
submit = { /*TODO*/ }, | ||
enableButton = true, // Define o botão como desativado | ||
) | ||
} | ||
|
||
composeTestRule.onNodeWithTag("dashedInputField_test").performTextInput(name) | ||
composeTestRule.onNodeWithTag("genderButtons_test").performClick() | ||
|
||
composeTestRule.onNodeWithTag("button3_test").assertIsEnabled() | ||
composeTestRule.onNodeWithTag("button3_test").performClick() | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
...ndroidTest/java/com/soujunior/petjournal/navigation/NavHostMainContentInstrumentedTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.rememberNavController | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.google.accompanist.pager.ExperimentalPagerApi | ||
import com.soujunior.petjournal.navigation.NavHostMock | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class NavHostMainContentInstrumentedTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private var navController = NavHostController(ApplicationProvider.getApplicationContext()) | ||
|
||
@OptIn(ExperimentalPagerApi::class) | ||
@Test | ||
fun navigateFrom_Home_to_accountManager(){ | ||
composeTestRule.setContent { | ||
navController = rememberNavController() | ||
NavHostMock(navController = navController, startDestination = "home") | ||
} | ||
|
||
composeTestRule.runOnUiThread { | ||
navController.navigate("accountManager") | ||
} | ||
|
||
assertEquals(navController.currentDestination?.route, "accountManager") | ||
|
||
} | ||
|
||
@Test | ||
fun navigateFrom_accountManager_to_tutorScreen(){ | ||
composeTestRule.setContent { | ||
navController = rememberNavController() | ||
NavHostMock(navController = navController, startDestination = "accountManager") | ||
} | ||
|
||
composeTestRule.runOnUiThread { | ||
navController.navigate("tutorScreen") | ||
} | ||
|
||
assertEquals(navController.currentDestination?.route, "tutorScreen") | ||
|
||
} | ||
|
||
@Test | ||
fun navigateFrom_tutorScreen_to_introRegisterPet(){ | ||
composeTestRule.setContent { | ||
navController = rememberNavController() | ||
NavHostMock(navController = navController, startDestination = "tutorScreen") | ||
} | ||
|
||
composeTestRule.runOnUiThread { | ||
navController.navigate("pets/introRegisterPet") | ||
} | ||
|
||
assertEquals(navController.currentDestination?.route, "pets/introRegisterPet") | ||
|
||
} | ||
|
||
@Test | ||
fun navigateFrom_introRegisterPet_to_speciesChoice(){ | ||
composeTestRule.setContent { | ||
navController = rememberNavController() | ||
NavHostMock(navController = navController, startDestination = "pets/introRegisterPet") | ||
} | ||
|
||
composeTestRule.runOnUiThread { | ||
navController.navigate("pets/speciesChoice") | ||
} | ||
|
||
assertEquals(navController.currentDestination?.route, "pets/speciesChoice") | ||
} | ||
|
||
@Test | ||
fun navigateFrom_speciesChoice_to_nameGenderScreen(){ | ||
composeTestRule.setContent { | ||
navController = rememberNavController() | ||
NavHostMock(navController = navController, startDestination = "pets/speciesChoice") | ||
} | ||
|
||
composeTestRule.runOnUiThread { | ||
val param = "Gato" | ||
navController.navigate("pets/nameAndGender/$param") | ||
} | ||
|
||
// Verifica se o NavController está no destino correto e se os parâmetros foram passados corretamente | ||
assertEquals(navController.currentDestination?.route, "pets/nameAndGender/{arg}") | ||
assertEquals(navController.currentBackStackEntry?.arguments?.getString("arg"), "Gato") | ||
} | ||
} |
Oops, something went wrong.