Search code examples
junit4

How to write Junit Test case for a method


I am very new to Junit testing,Kindly let me know how to mock this method and test in JUNIT:

enter image description here


Solution

  • Hi you can write test classes like this

    public class MyTests {    
      @Test
      public void multiplicationOfZeroIntegersShouldReturnZero() {
           MyClass tester = new MyClass(); // MyClass is tested
    
           // assert statements
           assertEquals(0, tester.multiply(10, 0), "10 x 0 must be 0");
           assertEquals(0, tester.multiply(0, 10), "0 x 10 must be 0");
           assertEquals(0, tester.multiply(0, 0), "0 x 0 must be 0");
      }
    }
    

    for more just check this link https://www.vogella.com/tutorials/JUnit/article.html