在Eclipse Android项目中无法运行JUnit 4测试用例 [英] Can't run JUnit 4 test case in Eclipse Android project

查看:247
本文介绍了在Eclipse Android项目中无法运行JUnit 4测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java的新手,正在尝试在我正在撰写的课程上运行单元测试。 Eclipse(3.5)为我创建了单元测试类,并将Junit4添加到我的课程路径。



我的类:

  public class DistanceUtil 
{

public static double metersToMiles(double meters)
{
return 0;
}
public static double metersToKilometers(double meters)
{
return 0;
}

}

我的单元测试:

  public class DistanceUtilTest {

@Test
public final void testMetersToMiles(){
失败(尚未实施); // TODO
}

@Test
public final void testMetersToKilometers(){
fail(尚未实现); // TODO
}

}

当我右键单击在单元测试并选择运行作为Junit测试我得到以下内容:

 
#一个致命的错误已经由Java运行时环境检测:

#内部错误(classFileParser.cpp:3075),pid = 5564,tid = 4940
#错误:ShouldNotReachHere()

#JRE版本:6.0_17-b04
#Java VM:Java HotSpot(TM)客户端虚拟机(14.3-b01混合模式windows-x86)
#保存更多信息的错误报告文件as:
#C:\Users\Giles Roadnight\workspaceAndroid\Cycloid\hs_err_pid5564.log

#如果您想提交错误报告,请访问:
#http://java.sun.com/webapps/bugreport/crash.jsp

任何人都知道如何解决这个问题?



谢谢

解决方案

在Google搜索了一个答案后,看起来可能有一些使用Android开发工具。



以下是从此评论线程:


  1. 右键单击项目 - >运行 - >运行配置

  2. 选择您的Junit项目

  3. 转到类路径选项卡

  4. 删除Android框架条目

  5. 选择引导条目

  6. 点击高级

  7. 选择添加图书馆

  8. 确定

  9. 选择JRE系统库

  10. 下一页

  11. 完成

  12. 您还需要添加JUnit库,按照步骤5到11并选择Junit而不是JRE System Library

  13. 您现在可以以Junit运行项目。


I am new to Java and am trying to run a unit test on a class I am writing. Eclipse (3.5) created the unit test class for me and added Junit4 to my class path.

My Class:

public class DistanceUtil 
{

public static double metersToMiles( double meters ) 
{
    return 0;
}
public static double metersToKilometers( double meters ) 
{
    return 0;
}

}

My unit test:

public class DistanceUtilTest {

@Test
public final void testMetersToMiles() {
    fail("Not yet implemented"); // TODO
}

@Test
public final void testMetersToKilometers() {
    fail("Not yet implemented"); // TODO
}

}

When I right click on the unit test and select run as Junit Test I get the following:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (classFileParser.cpp:3075), pid=5564, tid=4940
#  Error: ShouldNotReachHere()
#
# JRE version: 6.0_17-b04
# Java VM: Java HotSpot(TM) Client VM (14.3-b01 mixed mode windows-x86 )
# An error report file with more information is saved as:
# C:\Users\Giles Roadnight\workspaceAndroid\Cycloid\hs_err_pid5564.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

Anyone got an idea how I can fix this?

Thanks

解决方案

Having searched Google for an answer, this looks like it might have something to do with Android development tools.

Below are steps taken from this comment thread:

  1. Right click on the project -> run -> run configuration
  2. Select your Junit project
  3. Go to the classpath tab
  4. remove the Android framework entry
  5. select bootstrap entries
  6. click on advanced
  7. select Add Library
  8. Ok
  9. Chose "JRE System Library"
  10. Next
  11. finish
  12. You need to also add the JUnit library so follow the steps 5 to 11 and select the "Junit" instead of "JRE System Library"
  13. You can now run your project as Junit.

这篇关于在Eclipse Android项目中无法运行JUnit 4测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆