Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法解析静态方法junit断言_Java_Android_Junit_Junit4_Junit3 - Fatal编程技术网

Java 无法解析静态方法junit断言

Java 无法解析静态方法junit断言,java,android,junit,junit4,junit3,Java,Android,Junit,Junit4,Junit3,我已经尝试使用JUnit3.8和JUnit4。在Android文档中读到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: <?xml versio

我已经尝试使用JUnit3.8和JUnit4。在Android文档中读到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:

<?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>

我已经确认JUnit3.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());
}
}
import static org.junit.Assert.*;
导入java.util.HashMap;
导入java.util.Map;
导入junit.framework.TestSuite;
//导入org.junit.Before;
//导入org.junit.Test;
导入android.util.Log;
公共类NodeModTest扩展了TestSuite{
节点根=空;
节点a1=null;
节点a2=null;
节点a3=null;
节点a4=空;
//@以前
public void setUp()引发异常
{
Log.i(“aaa”,“在测试节点设置中”);
//节点a1=节点(节点父节点、字符串提示、映射子节点);
Mapchildren=newhashmap();
儿童。把(“a”,a1);
儿童。把(“b”,a2);
root=new节点(null,“stuff here”,children);
儿童。清除();
//这里有更多的代码。为简洁起见省略
}
//@试验
公共void testRunning()
{
Log.i(“aaa”,“在测试类中运行的测试”);
assertTrue(“启动并成功运行”,true);
}
//@试验
public void testAddNode(){
Log.i(“aaa”,“在测试类中添加节点”);
assertEquals(“子项的根数正确”,2,root.getChildren().size());
}
}

你知道我遗漏了什么吗?

我认为你应该使用junit.framework.Assert而不是org.junit.Assert。您可以看看这个

您应该删除
org.junit
下包的所有导入(静态或其他),并将测试更改为扩展
junit.framework.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());
  }
}
import java.util.HashMap;
导入java.util.Map;
导入junit.framework.TestCase;
导入android.util.Log;
公共类nodeModTest扩展了TestCase{
私有节点根;
专用节点a1;
专用节点a2;
专用节点a3;
专用节点a4;
@凌驾
受保护的void setUp()引发异常{
super.setUp();
Log.i(“aaa”,“在测试节点设置中”);
Mapchildren=newhashmap();
儿童。把(“a”,a1);
儿童。把(“b”,a2);
root=new节点(null,“stuff here”,children);
儿童。清除();
//这里有更多的代码。为简洁起见省略
}
公共void testRunning(){
Log.i(“aaa”,“在测试类中运行的测试”);
assertTrue(“启动并成功运行”,true);
}
public void testAddNode(){
Log.i(“aaa”,“在测试类中添加节点”);
assertEquals(“子项的根数正确”,2,root.getChildren().size());
}
}

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

您是否尝试过使用
Assert.assertTrue()
检查它是否与静态导入有关?@CarlosRobles,我刚刚尝试在所有断言都被注释掉的情况下运行测试(用print语句代替),我得到了错误:02-18 08:47:46.712:W/dalvikvm(9330):方法Landroid/test/InstrumentationTestRunner$StringResultPrinter;。打印错误覆盖Ljunit/textui/ResultPrint中同名的包私有方法;使用Junit3.8和Junit4.1,如果您与方法名称发生冲突,我将更改
import static org.junit.Assert.*
只导入org.junit.Assert.*并将所有函数调用更改为使用类名,例如将
assertTrue()
更改为
Assert.assertTrue()
以及相同的打印statements@CarlosRobles,我现在得到:VFY:无法解析静态方法3468:Lorg/junit/Assert;。当我导入org.junit.Assert时,assertEquals(Ljava/lang/String;JJ)V。@CarlosRobles,为了澄清我是这样做的:使用import junit.framework.Assert;给出了与使用JUnit3.8之前相同的错误。如果我切换到junit4.1(它允许我使用import org.junit.Assert.*;),我会得到:VFY:无法解析静态方法3469:Lorg/junit/Assert;。assertEquals(Ljava/lang/String;JJ)V