代码之家  ›  专栏  ›  技术社区  ›  KimKha Dimitar Dimitrov

不能用Eclipse运行junit

  •  7
  • KimKha Dimitar Dimitrov  · 技术社区  · 16 年前

    我用新的Eclipse。使用JUnit创建演示测试(我添加了默认的JUnit库内置Eclipse)。然后我写这个代码:

    import junit.framework.*;
    
    import org.junit.Test;
    
    public class SimpleTest extends TestCase { 
       public SimpleTest(String name) { 
          super(name);
       }
       public final void main(String method){
    
       }
    
       @Test
       public final void testSimpleTest() {
          int answer = 2;
          assertEquals((1+1), answer); 
       }
    }
    

    但它不运转。在“调试”选项卡中:

    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner at localhost:52754 
    Thread [main] (Suspended (exception ClassNotFoundException)) 
    URLClassLoader$1.run() line: not available [local variables unavailable] 
    AccessController.doPrivileged(PrivilegedExceptionAction<T>, AccessControlContext) line: not available [native method] 
    Launcher$AppClassLoader(URLClassLoader).findClass(String) line: not available 
    Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available 
    Launcher$AppClassLoader.loadClass(String, boolean) line: not available 
    Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available 
    

    我怎么解决这个问题?

    2 回复  |  直到 10 年前
        1
  •  5
  •   Gabriel Ščerbák    16 年前

    你,和许多人一样,把朱尼特3号和朱尼特4号搞混了。 如果您使用的是JUnit3,请将您的测试命名为“test*”,并从testcase继承。 如果您使用JUnit 4,请使用注释。

        2
  •  6
  •   BalusC    16 年前

    在调试模式下运行或仅在非调试模式下运行时,删除异常上的断点。

    在“调试”视图中,在右上框中单击 断点 标签和 取消检查 上的任何断点 Exception ,例如 ClassNotFoundException 然后重新运行测试。