Skip to content
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

Create base tests #1

Merged
merged 13 commits into from Oct 18, 2017
Merged

Create base tests #1

merged 13 commits into from Oct 18, 2017

Conversation

Serchinastico
Copy link
Contributor

🌀 Git merge message

  • Create tests for the MainActivity class
  • Create tests for the SuperHeroDetailActivity class
  • Configure dependencies to run espresso acceptance tests

Copy link
Member

@flipper83 flipper83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add only small cosmetic changes! really good job bro.


RecyclerViewInteraction.onRecyclerView<SuperHero>(withId(R.id.recycler_view))
.withItems(superHeroes)
.check({ (name), view, e -> matches(hasDescendant(withText(name))).check(view, e) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like use exception instead e, but it is not important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced


RecyclerViewInteraction.onRecyclerView<SuperHero>(withId(R.id.recycler_view))
.withItems(superHeroes)
.check({ (name), view, e -> matches(hasDescendant(withText(name))).check(view, e) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is name between parenthesis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a neat trick: https://kotlinlang.org/docs/reference/multi-declarations.html

We are basically destructuring the data class: (name, photo, isAvenger, description) ~=[iff 3 last properties are ignored] (name, _, _, _) ~= (name)


@Test
fun doesNotShowAvengersBadgeIfASuperHeroIsNotPartOfTheAvengersTeam() {
val superHeroes = givenThereAreSomeSuperHeroes(ANY_NUMBER_OF_SUPER_HEROES, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by default is false no? you don't need set this false arg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the default value, we are just making it explicit what we want. To me, removing the flag would mean we don't really care if they are avengers or not (I'm adding a name to the parameter to make that clear though)

}

private fun givenThereAreSomeAvengers(numberOfAvengers: Int): List<SuperHero> =
givenThereAreSomeSuperHeroes(numberOfAvengers, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I didn't remember bad in the screenshot tests, you use named arguments, like avengers = true. should be a good idea if we make it too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm going to make it explicit here too, good catch! 👌


private fun givenThereAreSomeSuperHeroes(numberOfSuperHeroes: Int = ANY_NUMBER_OF_SUPER_HEROES, avengers: Boolean = false): List<SuperHero> {
val superHeroes = LinkedList<SuperHero>()
for (i in 0 until numberOfSuperHeroes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in screenshot superhero we used IntRange(0, numberOfSuperHeroes - 1).map { id -> /**/} instead the for, I don't konw if you llike it or not. I more or less de same, but more kotlin stye.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

on(repository.getAllSuperHeroes()).thenReturn(emptyList<SuperHero>())
}

companion object {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we going to add companion objects in the top of the class or in the bottom?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it at the top of the classes just because 👍


@After
fun tearDown() {
val idlingResources = IdlingRegistry.getInstance().resources
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove this code?


@Test
fun doesNotShowAvengersBadgeIfSuperHeroIsNotPartOfTheAvengersTeam() {
val superHero = givenThereIsASuperHero(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you prefer use named arguments?

}

fun check(assertion: (item: A, view: View, e: NoMatchingViewException?) -> Unit): RecyclerViewInteraction<A> {
for (i in items.indices) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and use iitems.indices.forEach ??

return this
}

companion object {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same questions about companion objects, only for define a standard :)

@Serchinastico Serchinastico merged commit dc0e617 into master Oct 18, 2017
@Serchinastico Serchinastico deleted the create-tests branch October 18, 2017 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants