Eclipse 中的“未找到 JUnit 测试”
2022-08-31 20:06:40
所以我是JUnit的新手,我们必须用它来做家庭作业。我们的教授给了我们一个项目,有一个测试课, .当我右键单击>以JUnit测试>运行“时,我收到一个弹出错误,显示”找不到JUnit测试”。我知道这个问题已经在这里得到了回答(没有发现测试运行程序“JUnit 4”的测试),但是关闭日食,重新启动,清理和构建似乎不起作用。下面是我运行配置、生成路径和我正在尝试测试的类的屏幕截图。BallTest.java
BallTest.java
import static org.junit.Assert.*;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class BallTest {
Ball ball;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
System.out.println("Setting up ...");
Point2D p = new Point2D(0,0);
ball = new Ball(p);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
System.out.println("Tearing down ...");
ball = null;
}
/**
* Test method for {@link Ball#getCoordinates()}.
*/
@Test
public void testGetCoordinates() {
assertNotNull(ball); // don't need Assert. because of the import statement above.
Assert.assertEquals(ball.getCoordinates().getX(), 0);
Assert.assertEquals(ball.getCoordinates().getY(), 0);
}
/**
* Test method for {@link Ball#setCoordinates(Point2D)}.
*/
@Test
public void testSetCoordinates() {
Assert.assertNotNull(ball);
Point2D p = new Point2D(99,99);
ball.setCoordinates(p);
Assert.assertEquals(ball.getCoordinates().getX(), 99);
Assert.assertEquals(ball.getCoordinates().getY(), 99);
}
/**
* Test method for {@link Ball#Ball(Point2D)}.
*/
@Test
public void testBall() {
Point2D p = new Point2D(49,30);
ball = new Ball(p);
Assert.assertNotNull(ball);
Assert.assertEquals(ball.getCoordinates().getX(), 49);
Assert.assertEquals(ball.getCoordinates().getY(), 30);
//fail("Not yet implemented");
}
public static void main (String[] args) {
Result result = JUnitCore.runClasses(BallTest.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}