-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
ParameterizedTest
with name pattern specified relies on Locale.getDefault()
. This results in test names that possibly changing:
public class SimplifiedExample
{
@BeforeAll
static void before_all() { Locale.setDefault(Locale.US); }
@BeforeEach
void before_each() { Locale.setDefault(Locale.UK); }
@ParameterizedTest(name = "{0,number,currency}")
@ValueSource(ints = { 1_000, 2_000 })
void test1(int a)
{
// Test names with locale change:
// $1,000.00
// £2,000.00
}
}
It seems the first MessageFormat
is created after the call to BeforeAll
and before the call to BeforeEach
. As the Locale
cannot be set for a ParameterizedTest
your stuck with whatever the environments current default is.
It seems that the limited formatting is already down the "rabbit hole" @marcphilipp #1154
Add to this that the arguments formatted are those supplied by the provider before implicit or explicit conversion and not those supplied to the method then formatting is not very useful and certainly breaks the principle of least surprise.
As such I propose that formatting should support only place holders '{0} {1} etc...' until such time that @sbrannen #1154 support for formatting API is added.
Activity
sbrannen commentedon Sep 22, 2020
Tentatively slated for 5.8 M1 for team discussion
[-]ParameterizedTest formatting Locale sensative durring test[/-][+]ParameterizedTest formatting is Locale-sensitive[/+]marcphilipp commentedon Oct 30, 2020
Team decision: As documented, we pass the format expression to
MessageFormat
which uses the default locale. Thus, this works as designed and documented. If you run your tests on machines with different locales and want consistent test names, please set the JDK's locale via the standard system property. If you need to test with different locales, you could use Pioneer's@DefaultLocale
.