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

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

问题描述

我是 Java 新手,正在尝试对我正在编写的类运行单元测试.Eclipse (3.5) 为我创建了单元测试类并将 Junit4 添加到我的类路径中.

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.

我的班级:

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() {
    fail("Not yet implemented"); // TODO
}

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

}

当我右键单击单元测试并选择作为 Junit 测试运行时,我得到以下信息:

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:UsersGiles RoadnightworkspaceAndroidCycloidhs_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?

谢谢

推荐答案

在 Google 上搜索了答案,这看起来可能与 Android 开发工具有关.

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

以下是从 此评论线程:

  1. 右键单击项目 -> 运行 -> 运行配置
  2. 选择您的 Junit 项目
  3. 转到类路径选项卡
  4. 删除 Android 框架条目
  5. 选择引导条目
  6. 点击高级
  7. 选择添加库
  8. 好的
  9. 选择JRE 系统库"
  10. 下一步
  11. 完成
  12. 您还需要添加 JUnit 库,因此请按照步骤 5 到 11 操作并选择Junit"而不是JRE 系统库"
  13. 您现在可以作为 Junit 运行您的项目.

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

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