-
Notifications
You must be signed in to change notification settings - Fork 0
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 #2 from omer358/dev
write Instrumentation Tests for navigation and database
- Loading branch information
Showing
19 changed files
with
934 additions
and
124 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
22 changes: 0 additions & 22 deletions
22
app/src/androidTest/java/com/example/rememberme/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
app/src/androidTest/java/com/example/rememberme/data/PeopleDatabaseTest.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,131 @@ | ||
package com.example.rememberme.data | ||
|
||
import androidx.room.Room | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.SmallTest | ||
import com.example.rememberme.data.database.People | ||
import com.example.rememberme.data.database.PeopleDatabase | ||
import com.example.remindme.database.PeopleDao | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@SmallTest | ||
class PeopleDatabaseTest { | ||
|
||
private lateinit var database: PeopleDatabase | ||
private lateinit var peopleDao: PeopleDao | ||
|
||
@Before | ||
fun initDb() { | ||
database = Room.inMemoryDatabaseBuilder( | ||
ApplicationProvider.getApplicationContext(), | ||
PeopleDatabase::class.java | ||
).allowMainThreadQueries().build() | ||
|
||
peopleDao = database.peopleDao | ||
} | ||
|
||
@After | ||
fun closeDb() { | ||
if (this::database.isInitialized) { | ||
database.close() | ||
} | ||
} | ||
|
||
@Test | ||
fun insertAndGetPerson() = runBlocking { | ||
val person = People( | ||
firstName = "John", | ||
secondName = "Doe", | ||
place = "Park", | ||
time = "2023-06-13 10:00", | ||
note = "Met at the park", | ||
gender = "Male", | ||
avatar = 1 | ||
) | ||
|
||
peopleDao.insert(person) | ||
|
||
val retrievedPerson = peopleDao.getAll()[0] | ||
Assert.assertEquals(retrievedPerson.firstName, "John") | ||
Assert.assertEquals(retrievedPerson.secondName, "Doe") | ||
} | ||
|
||
@Test | ||
fun updatePerson() = runBlocking { | ||
val person = People( | ||
firstName = "John", | ||
secondName = "Doe", | ||
place = "Park", | ||
time = "2023-06-13 10:00", | ||
note = "Met at the park", | ||
gender = "Male", | ||
avatar = 1 | ||
) | ||
|
||
peopleDao.insert(person) | ||
|
||
val retrievedPerson = peopleDao.getAll()[0] | ||
retrievedPerson.firstName = "Jane" | ||
peopleDao.update(retrievedPerson) | ||
|
||
val updatedPerson = peopleDao.getAll()[0] | ||
Assert.assertEquals(updatedPerson.firstName, "Jane") | ||
} | ||
|
||
@Test | ||
fun deletePerson() = runBlocking { | ||
val person = People( | ||
firstName = "John", | ||
secondName = "Doe", | ||
place = "Park", | ||
time = "2023-06-13 10:00", | ||
note = "Met at the park", | ||
gender = "Male", | ||
avatar = 1 | ||
) | ||
|
||
peopleDao.insert(person) | ||
|
||
val retrievedPerson = peopleDao.getAll()[0] | ||
peopleDao.removePerson(retrievedPerson.id) | ||
|
||
val people = peopleDao.getAll() | ||
Assert.assertTrue(people.isEmpty()) | ||
} | ||
|
||
@Test | ||
fun clearAllPeople() = runBlocking { | ||
val person1 = People( | ||
firstName = "John", | ||
secondName = "Doe", | ||
place = "Park", | ||
time = "2023-06-13 10:00", | ||
note = "Met at the park", | ||
gender = "Male", | ||
avatar = 1 | ||
) | ||
|
||
val person2 = People( | ||
firstName = "Jane", | ||
secondName = "Doe", | ||
place = "Mall", | ||
time = "2023-06-13 12:00", | ||
note = "Met at the mall", | ||
gender = "Female", | ||
avatar = 2 | ||
) | ||
|
||
peopleDao.insertAll(person1, person2) | ||
|
||
peopleDao.clear() | ||
val people = peopleDao.getAll() | ||
Assert.assertTrue(people.isEmpty()) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/androidTest/java/com/example/rememberme/presentation/navgraph/NavGraphTest.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,37 @@ | ||
package com.example.rememberme | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.example.rememberme.presentation.navgraph.NavGraph | ||
import com.example.rememberme.presentation.navgraph.Routes | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class NavGraphTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testNavigationToOnBoardingScreen() { | ||
composeTestRule.setContent { | ||
NavGraph(startDestination = Routes.AppStartNavigation.route) | ||
} | ||
|
||
composeTestRule.onNodeWithText("OnBoarding Screen").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun testNavigationToPeopleScreen() { | ||
composeTestRule.setContent { | ||
NavGraph(startDestination = Routes.PeopleNavigation.route) | ||
} | ||
|
||
composeTestRule.onNodeWithTag("PeopleListScreen").assertIsDisplayed() | ||
} | ||
} |
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
Oops, something went wrong.