11

Eclipse で JUnit 4 と Robolectric を使用してテストを実行しようとしていますが、常に次のエラーが表示されます。

Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (javaClasses.cpp:129), pid=3546, tid=140317899335424
#  fatal error: Invalid layout of preloaded class
#
# JRE version: 7.0_07-b10
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.3-b01 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#

私のテストはとても簡単です。すべての作業をチェックするためだけです:

@RunWith(RobolectricTestRunner.class)
public class FormatTest {

    @Test
    public void getFormatElapsedTimeOnSecondsTest(){
        assertEquals("3seg","3seg");
    }
}

私のシステムにインストールされているJavaは次のとおりです。

java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

何が起こるかわかりません。

4

6 に答える 6

21

これはあなたの問題ではないかもしれませんが、Run As -> Android Application を使用してこれを乗り越えることができました。

ただし、Androidを使用しているかどうかはわかりません。おそらく、他の問題について実行構成を確認してください。

于 2012-09-26T18:49:38.323 に答える
12

実行構成を修正する必要があります。

JUnit テストを実行する場合

"right click on test class in the package explorer"->"Run As"->"JUnit Test"

Android プロジェクトでは、「Android JUnit Test Launcher」をランチャーとして設定する必要があります。起動構成のタイプが「JUnit」であっても、そのAndroidランチャーを使用する必要があります。

次の場所にあります。

"right click on test class in the package explorer"->"Properties"->"Run/Debug Settings"->"Edit..." 


テスト:

import junit.framework.TestCase;

public class ExampleTest extends TestCase{
public ExampleTest(String name){
    super(name);
}

protected void setUp() throws Exception{
    super.setUp();
}

protected void tearDown() throws Exception{
    super.tearDown();
}

public void testFoo(){
    fail("Not yet implemented");
}

}

実行構成を作成します。

"Run"->"Run Configurations..."->"Right click on JUnit"->"New"->"Set project and Test class"->"Select Android JUnit Test Launcher"->"Run"

注意: x86 jdk を使用している場合、ランチャーが「Eclipse JUnit Launcher」に設定されていると、次のエラーが発生します。

    Invalid layout of java.lang.String at value
    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    #  Internal Error (javaClasses.cpp:129), pid=3844, tid=4828
    #  fatal error: Invalid layout of preloaded class
    #
    # JRE version: 7.0_17-b02
    # Java VM: Java HotSpot(TM) Client VM (23.7-b01 mixed mode windows-x86 )
    # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
于 2013-04-05T17:56:44.497 に答える
3

私にとっては解決策でした: Run -> Run Configurations... ->タブ Test でSelect Preferred Launcherをクリックし、 Use configuration specific settings with selection Android JUnit Test Launcherを選択します。

JUnit の下のすべてのエントリを削除します ([実行構成] ダイアログの左の列、RightMouse - 削除)。

次にRun as -> JUnit Testを選択し、必要に応じて Use configuration specific settings with Android JUnit Test Launcher を選択します。

于 2013-09-04T06:24:54.497 に答える
1

メインのJavaクラスを右クリックし、構成を実行してから、クラスパスタブに移動し、そこでAndroidライブラリを削除します。次に実行します。

これが役立つことを願っています。

于 2013-08-18T00:13:53.050 に答える