简体   繁体   English

无法使用Eclipse运行jUnit

[英]Can't run jUnit with Eclipse

I use new Eclipse. 我使用新的Eclipse。 Create demo test with jUnit (I added default jUnit library built-in Eclipse). 使用jUnit创建演示测试(我添加了默认的jUnit库内置Eclipse)。 Then I write this code: 然后我写这段代码:

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); 
   }
}

But it doesn't run. 但它没有运行。 In the Debug tab: 在“调试”选项卡中:

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 

How can I solve this? 我怎么解决这个问题?

Remove the breakpoints on Exceptions when running in debug mode, or just run in non-debug mode. 在调试模式下运行时删除异常上的断点,或者只在非调试模式下运行。

In the debug view, on the right top box click the Breakpoints tab and uncheck any breakpoint on an Exception , eg ClassNotFoundException and rerun the test. 在调试视图中,在右上角的框中单击Breakpoints选项卡并取消选中 Exception上的任何断点,例如ClassNotFoundException并重新运行测试。

You, as many people, have confused the JUnit 3 and JUnit 4. If you are using JUnit 3 name your tests "test*" and inherit from TestCase. 您和许多人一样,混淆了JUnit 3和JUnit 4.如果您使用JUnit 3,则将测试命名为“test *”并从TestCase继承。 If you are using JUnit 4 use annotations. 如果您使用的是JUnit 4,请使用注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM