You have a number of problems:
- you are trying to call a static static method
- java method names are case sensitive and you have mixed up this thing.
I fixed some things for you and just checked the code below:
OddEven.java:
public class OddEven { public boolean evenNum(double num) { if(num%2 == 0) { System.out.print(true); return true; } else { System.out.print(false); return false; } } }
OddEvenTest.java
import static org.junit.Assert.*; import org.junit.Test; public class OddEvenTest { @Test public void testEvenNum() { boolean ans = true; boolean val; double num = 6; OddEven oddEven = new OddEven(); val = oddEven.evenNum(num); assertEquals(ans,val); } }
Assuming that System.out.println() calls in OddEven strictly for debugging, all of this can be collapsed to:
OddEven.java
public class OddEven { public boolean evenNum(double num) { return num%2 == 0; } }
OddEvenTest.java
import static org.junit.Assert.*; import org.junit.Test; public class OddEvenTest { @Test public void testEvenNum() { OddEven oddEven = new OddEven(); assertTrue(oddEven.evenNum(6)); assertFalse(oddEven.evenNum(5)); } }
Now the code is shorter, and unit test is even an odd case for good measure.
source share