3

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:

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>

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:

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?

Rilcon42
  • 9,584
  • 18
  • 83
  • 167
  • HAve you tried with `Assert.assertTrue()` to check if it is something with the static import? – Carlos Robles Feb 17 '14 at 22:05
  • @CarlosRobles, I just tried to run the test with all Asserts commented out (with print statements in their place) and I got the error: 02-18 08:47:46.712: W/dalvikvm(9330): method Landroid/test/InstrumentationTestRunner$StringResultPrinter;.print incorrectly overrides package-private method with same name in Ljunit/textui/ResultPrinter; using Junit3.8 and Junit4.1 – Rilcon42 Feb 18 '14 at 13:52
  • you have a conflict with method names, i would change the `import static org.junit.Assert.*;` to just `import org.junit.Assert.*;` and change all the funcion calls to use the class name, for instance change `assertTrue()` to `Assert.assertTrue()` and the same the print statements – Carlos Robles Feb 18 '14 at 13:58
  • @CarlosRobles, I now get: VFY: unable to resolve static method 3468: Lorg/junit/Assert;.assertEquals (Ljava/lang/String;JJ)V when I import org.junit.Assert. – Rilcon42 Feb 18 '14 at 15:04
  • @CarlosRobles, to try to clarify I did this: using import junit.framework.assert; gives me the same error as before using junit 3.8. If i switch to junit4.1 (which lets me use import org.junit.Assert.*;) I get: VFY: unable to resolve static method 3469: Lorg/junit/Assert;.assertEquals (Ljava/lang/String;JJ)V – Rilcon42 Feb 18 '14 at 15:11
  • sorry i told you to import import org.junit.Assert.*; but it is import org.junit.Assert; What happens if you ctrl+click in the assertEquals method? an eclipse open it? doeas at least recognize it? – Carlos Robles Feb 18 '14 at 15:11
  • I think I edited my prior comment to answer your question after you had asked it. sorry about that. – Rilcon42 Feb 18 '14 at 15:15
  • Im lost now. Could it be that teh classes are not correcty exported? take a look at this answer http://stackoverflow.com/a/21838559/2357411 – Carlos Robles Feb 18 '14 at 15:23
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47786/discussion-between-rilcon42-and-carlos-robles) – Rilcon42 Feb 18 '14 at 17:40

2 Answers2

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

Totò
  • 1,824
  • 15
  • 20
0

You should remove all imports (static and otherwise) for packages under org.junit and change your test to extend 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());
  }
}

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

NamshubWriter
  • 23,549
  • 2
  • 41
  • 59