Errata for Android Test-Driven Development by Tutorials 1st Edition

Creating this topic to catch any typos and bugs in the 1st Edition of Android Test-Driven Development by Tutorials.

Hi. p106 of the digital edition of the book (Chapter 6 : Architecting for Testing)

interface Space

data class RectangularSpace(val width: Double, val height: Double): Space

data class CircularSpace(radius: Double): Space

class ArchitectUtils {
	...
	fun calculateArea(spaces: List<Space>) {
		var total = 0
		for (space in spaces) {
			if (space is SquareSpace) {
				total += space.width * space.height
			} elseif (space is CircularSpace) {
				total += space.radius * space.radius * PI
			}
		}
		return total
	}
}

I believe it should be

if (space is RectangularSpace)

not SquareSpace

Section II, before Chapter 4, rendering issue:

(Apple Books)

Chapter 3, before the section “Refactor: Updating your code”

“This mean you need to update the function so it returns null again when given null as a parameter while ensuring your newest test is passing.”

Should be “This means…”

@ellem @abunur Thank you for the heads up - much appreciated! I will forward this to the book team.

In Chapter 7, at the bottom of the screenshot on page 184 it says: “show the next question”. On the next page in the book the UnitTest and CocktailViewModel are using the current question to update the LifeData and verify.

So should the test contain the following extra line for setup?
whenever(game.nextQuestion()).thenReturn(nextQuestion)

and the verification then becomes:
verify(questionObserver).onChanged(nextQuestion)

and the CocktailViewModel answerQuestion method should therefor contain:

nextQuestion() instead of questionLiveData.value = question ?

Chapter 6,
Architectural design patterns “Under MVVM”
private val loginStatus: MutableLiveData()
it should be
private val loginStatus = mutableLiveData()
or
private val loginStatus : MutableLiveData =mutableLiveData()

Chapter 3, first unit test:

In the first unit test, for the section making the test pass, the provided code does not make the test pass. The code provided throws the following error:

Null can not be a value of a non-null type Unit

The function needs to specify a nullable return type, such as URL? or String?, otherwise it defaults to the return type for any Kotlin function that doesn’t explicitly provide one (Unit).

So the following would work instead:

fun getSearchUrl(query: String?): String? {
	return null
} 

Thanks for reporting this, @abunur!