Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

UnitTest for int function failed

I'm trying to create a unit test for simple class that contain function which return number and this is the function:

public static int Result(){

// code of function here it return value equal to 99

        return output;
    }

and this is my main method where I call this method and print it's result:

public static void main(String[] args) {

        System.out.println("result is= " + Result()); 

    }

and when I run the program the output that I get in run is 99

now in my test class this is my test code for Result() function:

@Test
    public void testResult() {

        System.out.println("Result");
        int expResult = 99;
        int result = javaClass.Result();
        assertEquals(expResult, result);
    }

and this is the other code nad methods of test class:

JavaTask javaTask;

    public JavaTaskTest() {
    }

    @Before
    public void setUp() {
        javaTask = new JavaTask();
    }

    @After
    public void tearDown() {
        javaTask = null;
    }

When I run the test I got this error:

testResult Failed: expected <99> but was <200>

why I got the result from the JavaClass different in test class than the result that really returned by same function in JavaClass when I run it

Comments