I have this code
@Test
fun price_twelve_cupcakes() {
val viewModel = OrderViewModel()
viewModel.setQuantity(12)
viewModel.price.observeForever {}
assertEquals("$27,00", viewModel.price.value)
}
And I get this Error
And This Comparison Failure
I encountered the same issue with the NBSP sign! Spent some time to figure out what to do with the tests
TL;DR:
So
assertEquals("27,00 Br", priceToCheck)
should become
assertEquals("27,00\u00A0Br", priceToCheck)
Also note that different locales not only have different grouping sign (comma, dot, space, NBSP etc.) but also a different cents separator (comma, dot)
It's caused by Locale's string formatting settings and involves DecimalFormat, String.format, NumberFormat.getCurrencyInstance() If you want your string to be formatted in a stable way no matter what default locale is set, you can use either DecimalFormat(pattern of choice) or pass the Locale you want (say Locale("en","IE") for Ireland)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With