-
Notifications
You must be signed in to change notification settings - Fork 259
Enable and introduce kotlin test fixtures #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: studio-main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,6 @@ kotlin.code.style=official | |
| # resources declared in the library itself and none from the library's dependencies, | ||
| # thereby reducing the size of the R class for that library | ||
| android.nonTransitiveRClass=true | ||
| # Enbale test kotlin fixtures | ||
| # Can't find official documentation https://emartynov.medium.com/android-project-test-fixtures-dec50c5d8533 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://issuetracker.google.com/issues/259523353#comment21 might worth a mention? (The thread has a lot of info)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to mention compatibility with tooling versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean that's the most official doc we have.
emartynov marked this conversation as resolved.
Outdated
|
||
| android.experimental.enableTestFixturesKotlinSupport=true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import com.google.common.truth.Truth | ||
|
|
||
| import com.example.android.recipes.fixtureLib.R as AppR | ||
|
|
||
| class KotlinUserRepoFixture { | ||
| private val users: MutableMap<Int, User> = | ||
| HashMap() | ||
|
|
||
| init { | ||
| users[1] = User(1, "Bob", "Wilson", "active") | ||
| users[2] = User(2, "John", "Johnson", "vacation") | ||
| } | ||
|
|
||
| val repository: UserRepository | ||
| get() = object : UserRepository { | ||
| private val events: MutableList<Int> = | ||
| ArrayList() | ||
|
|
||
| override fun getUsers(): List<User> { | ||
| return ArrayList(users.values) | ||
| } | ||
|
|
||
| override fun updateUser(user: User) { | ||
| users[user.id] = user | ||
| events.add(AppR.string.userUpdated) | ||
| } | ||
|
|
||
| override fun getUserEvents(): List<Int> { | ||
| return ArrayList(events) | ||
| } | ||
| } | ||
|
|
||
| fun getUsers(): List<User> { | ||
| return ArrayList(users.values) | ||
| } | ||
|
|
||
| fun inDataSet(user: User) { | ||
| Truth.assertThat(users[user.id]).isEqualTo(user) | ||
| } | ||
|
|
||
| fun assertEventIsUpdateUser(event: Int) { | ||
| Truth.assertThat(event) | ||
| .isEqualTo(AppR.string.userUpdated) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.