【问题标题】:Android - Code coverage test errorsAndroid - 代码覆盖测试错误
【发布时间】:2013-12-01 20:43:11
【问题描述】:

到目前为止,我一直在尝试让代码覆盖率测试在 IntelliJ 中工作几个小时,但没有成功。

首先: 项目中不包含junit的“Run with coverage>”会产生以下错误(显然)

线程“main”中的异常 java.lang.NoClassDefFoundError: junit/textui/ResultPrinter

将 junit 4.11 和 hamcrest-core 1.3 添加到库中,然后“运行覆盖”:

!!!预计 JUnit 版本 3.8 或更高版本:

java.lang.RuntimeException: 存根!

现在,我已经阅读了更改模块选项中的依赖顺序可以解决此问题。 所以在更改顺序后,我得到了这个错误:

junit.framework.AssertionFailedError: Exception in constructor: testMakeTextView (java.lang.NoClassDefFoundError: be/dave/DiversoScoreApp/MyActivity
at be.dave.DiversoScoreApp.MyActivityTest.<init>(MyActivityTest.java:20)

指向下面的代码:

public class MyActivityTest extends ActivityInstrumentationTestCase2<MyActivity> {
MyActivity myActivity;

public MyActivityTest() {
    super("be.dave.DiversoScoreApp", MyActivity.class);
}

@Override
public void setUp() throws Exception {
    super.setUp();
    myActivity = getActivity();
}

public void testMakeTextView() throws Exception {
    TextView textView = myActivity.makeTextView("Test-text", 50);
    TextView textView1 = myActivity.makeTextView("Diverso", 75);
    assertEquals("TextView Text should be correct", textView.getText(), "Test-text");
    assertNotSame("TextView Text should fail", textView1.getText(), "Not Diverso");
    } 
}

我已经用谷歌搜索和搜索了,但是到目前为止我还没有找到任何解决方案。

【问题讨论】:

    标签: java android unit-testing junit intellij-idea


    【解决方案1】:

    如果您尝试测试 testMakeTextView 方法,您应该使用 @Test 符号对其进行注释。 所以

    @Test
    public void testMakeTextView()
    

    setUp() 方法也有一个@Before 注释,而不是我认为的@Override。

    【讨论】:

    • 我都更改了你的建议,但遗憾的是 NoClassDefFoundError 仍然存在
    • 您是否将 hamcrest 添加到运行时路径?
    • 我已将 JUnit 和 hamcrest 添加到项目的库中,如果您是这个意思?
    • 在这里,试试这个,看看它是否有效:stackoverflow.com/questions/8678630/…
    • 恐怕IntelliJ中没有提供的选项,我发现的唯一东西是“src”和“gen”源文件夹,它们按照答案指定的顺序排列。 (d.pr/i/Ea4l) 要么,要么我完全失明......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 2010-09-12
    • 2021-02-08
    相关资源
    最近更新 更多