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

ParameterizedTest formatting is Locale-sensitive #2417

Closed
johnsoneal opened this issue Sep 22, 2020 · 2 comments
Closed

ParameterizedTest formatting is Locale-sensitive #2417

johnsoneal opened this issue Sep 22, 2020 · 2 comments

Comments

@johnsoneal
Copy link

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.

@sbrannen
Copy link
Member

Tentatively slated for 5.8 M1 for team discussion

@sbrannen sbrannen changed the title ParameterizedTest formatting Locale sensative durring test ParameterizedTest formatting is Locale-sensitive Sep 22, 2020
@marcphilipp
Copy link
Member

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.

@marcphilipp marcphilipp removed this from the 5.8 M1 milestone Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants