Issue
I'm a beginner to Java. I wrote a simple program, below one. But I am getting compilation errors.
Java Class:
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));
}
}
Test File:
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();
}
}
Errors:
`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`
I googled for a solution but still stuck at that error. So please help me. What should I do now?
Solution
You need to add junit jar.It is missing.
You can download junit jar at https://mvnrepository.com/artifact/junit/junit/4.11 and download the jar
or if you are using maven add the dependency in pom.
Answered By - tarun