I have a class called Calculator
, the code is as below and it can be compiled successfully.
public class Calculator {
private static int result;
public void add(int n) {
result = result + n;
}
public void substance(int n) {
result = result - 1; // just a bug for some purpose
}
... .... // some other methods
}
I have another class called CalculatorTest.java
using Junit4 to test Calculator
, whose code is as
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class CalculatorTest {
private static Calculator ca = new Calculator();
// initialise
@Before
public void setUp() throws Exception {
ca.clear();// clear the result
}
@Test
public void testAdd() {
// fail("Not yet implemented");
ca.add(2);
ca.add(3);
assertEquals(5, ca.getResult());
}
@Test
public void testSubstance() {
// fail("Not yet implemented");
ca.add(10);
ca.substance(5);
assertEquals(5, ca.getResult());
}
... .... // some other methods
}
In the terminal, I run:
javac -cp /usr/share/java/junit4.jar CalculatorTest.java
The result is :
CalculatorTest.java:12: error: cannot find symbol
private static Calculator ca = new Calculator();
^
symbol: class Calculator
location: class CalculatorTest
CalculatorTest.java:12: error: cannot find symbol
private static Calculator ca = new Calculator();
^
symbol: class Calculator
location: class CalculatorTest
2 errors
So, what the problem can be?
The spelling is correct and Calculator is not a java keyword.
Thank you.