无法解析静态方法junit断言

时间:2022-09-04 11:04:24

I have tried using both Junit 3.8 and Junit 4. After reading in the Android docs that Android is not updated for Junit4 I downgraded to 3.8. I am persistently getting this error:

我尝试过使用Junit 3.8和Junit 4。在安卓文档中阅读后,Android没有更新到Junit4,我降级为3.8。我一直在犯这样的错误:

02-17 16:37:27.409: W/dalvikvm(32014): VFY: unable to resolve static method 3467: Lorg/junit/Assert;.assertTrue (Ljava/lang/String;Z)V

AndroidManifest.xml:

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kronosDev.nodeMud"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.kronosDev.nodeMud"
android:label="Kronos Tests" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

        <uses-library android:name="android.test.runner" />

    <activity
        android:name="com.kronosDev.nodeMud.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

I have confirmed that the junit 3.8 (and Junit4) are on the build path as external JAR's. I have tried including each jar individually with no result. My test code:

我已经确认了junit 3.8(和Junit4)作为外部JAR在构建路径上。我试过把每个罐子单独装上,但没有结果。我的测试代码:

import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestSuite;
//import org.junit.Before;
//import org.junit.Test;

import android.util.Log;

public class NodeMudTest extends TestSuite{

Node root=null;
Node a1=null;
Node a2=null; 
Node a3=null;
Node a4=null;   

//@Before
public void setUp() throws Exception 
{
    Log.i("aaa","in setup for testing node");
    //Node a1=Node(Node parent,String prompt,Map<String,Node>children); 
    Map<String,Node>children=new HashMap<String,Node>();

    children.put("a",a1);
    children.put("b",a2);
    root=new Node(null,"stuff here",children);
    children.clear();
//more code here. omitted for brevity

}

//@Test
public void testRunning()
{
    Log.i("aaa","test running in test class");
    assertTrue("up and running successfully",true);
}

//@Test
public void testAddNode() {
    Log.i("aaa","in add node in test class");
    assertEquals("root number of children correct", 2, root.getChildren().size());
}
}

Any idea what I am missing?

知道我错过了什么吗?

2 个解决方案

#1


1  

I think you should use junit.framework.Assert instead of org.junit.Assert. You can have a look at this http://developer.android.com/reference/junit/framework/Assert.html

我认为你应该使用junit.frame . assert而不是org.junit.Assert。您可以查看http://developer.android.com/reference/junit/framework/Assert.html

#2


0  

You should remove all imports (static and otherwise) for packages under org.junit and change your test to extend junit.framework.TestCase

您应该删除org下包的所有导入(静态和其他)。并更改测试以扩展junit.frame . testcase

import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

import android.util.Log;

public class NodeMudTest extends TestCase {
  private Node root;
  private Node a1;
  private Node a2; 
  private Node a3;
  private Node a4;   

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    Log.i("aaa", "in setup for testing node");
    Map<String,Node>children=new HashMap<String,Node>();

    children.put("a", a1);
    children.put("b", a2);
    root = new Node(null, "stuff here", children);
    children.clear();
    //  more code here. omitted for brevity
  }

  public void testRunning() {
    Log.i("aaa", "test running in test class");
    assertTrue("up and running successfully", true);
  }

  public void testAddNode() {
    Log.i("aaa", "in add node in test class");
    assertEquals("root number of children correct", 2, root.getChildren().size());
  }
}

In addition, only put one JUnit jar on your classpath.

此外,在类路径中只放置一个JUnit jar。

#1


1  

I think you should use junit.framework.Assert instead of org.junit.Assert. You can have a look at this http://developer.android.com/reference/junit/framework/Assert.html

我认为你应该使用junit.frame . assert而不是org.junit.Assert。您可以查看http://developer.android.com/reference/junit/framework/Assert.html

#2


0  

You should remove all imports (static and otherwise) for packages under org.junit and change your test to extend junit.framework.TestCase

您应该删除org下包的所有导入(静态和其他)。并更改测试以扩展junit.frame . testcase

import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

import android.util.Log;

public class NodeMudTest extends TestCase {
  private Node root;
  private Node a1;
  private Node a2; 
  private Node a3;
  private Node a4;   

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    Log.i("aaa", "in setup for testing node");
    Map<String,Node>children=new HashMap<String,Node>();

    children.put("a", a1);
    children.put("b", a2);
    root = new Node(null, "stuff here", children);
    children.clear();
    //  more code here. omitted for brevity
  }

  public void testRunning() {
    Log.i("aaa", "test running in test class");
    assertTrue("up and running successfully", true);
  }

  public void testAddNode() {
    Log.i("aaa", "in add node in test class");
    assertEquals("root number of children correct", 2, root.getChildren().size());
  }
}

In addition, only put one JUnit jar on your classpath.

此外,在类路径中只放置一个JUnit jar。