3

ソフトウェアのいくつかの機能をテストしており、その一部はロケールで動作しています。そのため、マシンでテストすると、すべてのテストが実行されますが、Jenkins では、ロケール (Java ロケール) を使用した一部のテストが失敗します。

次に例を示します。

@Test
public void testCurrencyFormat_withCLPFormat_returnValidFormat() {

    BigDecimal amount = new BigDecimal("500456.789");
    java.util.Currency currency = java.util.Currency
            .getInstance(chileLocale);
    Currency c = new Currency(currency);

    assertEquals("500.456,789",
            defaultCurrencyFormatter.format(c, amount, chileLocale));

} 

設定されているロケールは、テストに適切なロケールを使用することに注意してください。私が言ったように、私のマシンではテストは問題なく実行されましたが、ジェンキンスでは失敗しました:

org.junit.ComparisonFailure: expected:<500[.456,]789> but was:<500[,456.]789>
at org.junit.Assert.assertEquals(Assert.java:125)
at org.junit.Assert.assertEquals(Assert.java:147)
at cl.taisachile.antaios.domain.currency.CurrencyTest.testCurrencyFormat_withCLPFormat_returnValidFormat(CurrencyTest.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

編集:

サーバー上で手動でテストを実行します。CentOS で yum を使用して jenkins をインストールしたので、Jenkins には独自のユーザーがいます。サーバーへのデフォルトのログインユーザーを使用してテストを実行すると、すべて問題なく実行されます。しかし、jenkins ユーザーにログインすると、テストが失敗します。jenkisやコードではないと思います。しかし、どこが違うのかわかりません。ヘルプはありますか?

前もって感謝します。

編集 2: 記録のために: サーバーのセットアップを変更したところ、エラーは消えました。いくつかの構成をテストしましたが、centos/32 ビットで失敗する理由を特定できませんでした。全てに感謝。

4

1 に答える 1

1

テスト (Jenkins) マシンにインストールされている Java のバージョンの問題かもしれませんし、コードの問題かもしれません。

chileLocaleがどのようにインスタンス化されるかを示していません。問題がある可能性があります。defaultCurrencyFormatterまた、テスト中のandCurrencyオブジェクトのコードも表示しません。

このテストでは、es-CL ロケールの小数点およびグループ区切り記号のシステム定義が表示されます。

public static void main(String[] args) {
    Locale chileLocale = new Locale("es", "CL");
    DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(chileLocale);

    char sep = formatter.getDecimalFormatSymbols().getDecimalSeparator();
    char grp = formatter.getDecimalFormatSymbols().getGroupingSeparator();

    System.out.println("Separator: " + sep + " Grouping: " + grp);
}

システムによって異なる場合は、Java のインストールを確認する必要があります。これが明らかに問題です。

EDIT: 別の注意:標準のJavaNumberFormatとその派生物はスレッドセーブではないことに注意してください。異なるスレッドから同じフォーマッタ インスタンスにアクセスしている場合、問題が発生する可能性があります。スレッドごとに 1 つのフォーマッタ インスタンスがあることを確認してください。

于 2013-10-23T14:43:50.880 に答える