我试图在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)
我不明白发生什么。
这可能不是你的问题,但我可以通过使用运行方式来突破这个 - > Android应用程序。
但是,我不知道,如果你使用的是Android或没有。 可能是检查其他问题Run配置。
您需要更正你的运行配置。
如果要运行用JUnit测试
"right click on test class in the package explorer"->"Run As"->"JUnit Test"
在Android项目,你需要设置的“Android JUnit测试启动”为启动。 你已经做使用,即使你的启动配置有型“的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"
注意:如果您使用的是86 jdk的,如果你的启动设置为“Eclipse的JUnit的启动器”,您将收到以下错误:
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
对我来说,是解决办法: 运行- >运行配置- >在标签测试单击选择首选启动 ,并与选择的Android JUnit测试启动器中选择使用配置的具体设置 。
删除所有条目下的JUnit(运行配置对话框的左边一列; RIGHTMOUSE - 删除)。
然后运行方式- 与Android JUnit测试启动 > JUnit测试 ,并选择性地选择使用配置的具体设置 。
与主,运行配置右键单击Java类,然后去Classpath选项卡中,去掉了Android图书馆里。 然后运行。
我希望这有帮助。
它会更容易。 该杀运行 - >配置和寻找JUnit和Android的JUnit测试。 删除你的配置,如果它的存在。 那么下一次你点击运行它会问有关配置。 您先选择JUnit和然后在接下来的对话激活“使用配置特定设置”,然后选择Android的JUnit测试Laucher。
同样的问题遇到了对我以及和原因是我在Android项目加入主(一个String [])方法。
所以,刚刚从项目中删除主(一个String [])方法,并为运行Android应用程序。