软件包“ junit.framework”不存在

时间:2019-10-01 04:02:10

标签: java junit compilation

我是Java的初学者。我写了一个简单的程序,下面一个。但是我遇到编译错误。

Java类:

  public class Return{
    public static int fibonacci(int n){
      if (n == 1 || n == 2){
        return 1;
      }
      return fibonacci(n - 1) + fibonacci(n - 2);
    }
    public static void main(String[] args) {
      System.out.println(fibonacci(6));
    }
  }

测试文件:

import junit.framework.TestCase;

public class ReturnTest extends TestCase{
  public static  void testFibonacci(){
    assertEquals(1, Return.fibonacci(1));
    assertEquals(1, Return.fibonacci(2));
    assertEquals(1, Return.fibonacci(3));
  }
  public static void main(String[] args){
    testFibonacci();
  }
}

错误:

`ReturnTest.java:1: error: package junit.framework does not exist
import junit.framework.TestCase;
                  ^
ReturnTest.java:3: error: cannot find symbol
public class ReturnTest extends TestCase{
                            ^
  symbol: class TestCase
ReturnTest.java:5: error: cannot find symbol
    assertEquals(1, Return.fibonacci(1));
    ^
  symbol:   method assertEquals(int,int)
  location: class ReturnTest
ReturnTest.java:6: error: cannot find symbol
    assertEquals(1, Return.fibonacci(2));
    ^
  symbol:   method assertEquals(int,int)
  location: class ReturnTest
ReturnTest.java:7: error: cannot find symbol
    assertEquals(1, Return.fibonacci(3));
    ^
  symbol:   method assertEquals(int,int)
  location: class ReturnTest
5 errors`

我用Google搜索解决方案,但仍然停留在该错误上。所以请帮帮我。我现在该怎么办?

1 个答案:

答案 0 :(得分:0)

您需要添加junit jar。找不到。

您可以从https://mvnrepository.com/artifact/junit/junit/4.11下载junit jar并下载jar

或者如果您正在使用maven,则将依赖项添加到pom中。