I try my best to learn Mockito in order to remove the application. The following is an example of the im method that is currently trying to verify
public boolean validateFormula(String formula) { boolean validFormula = true; double result = 0; try { result = methodThatCalculatAFormula(formula, 10, 10); } catch (Exception e) { validFormula = false; } if (result == 0) validFormula = false; return validFormula; }
This method calls another method in the same class methodThatCalculatAFormula , which I do not want to call when I unittest validateFormula .
To test this, I would like to see how this method behaves depending on what methodThatCalculatAFormula returns. Since it returns false when result is 0, and returns a value if it is some number but 0, I would like to simulate these return values ββwithout running the actual methodThatCalculatAFormula method.
I wrote the following:
public class FormlaServiceImplTest { @Mock FormulaService formulaService; @Before public void beforeTest() { MockitoAnnotations.initMocks(this); } @Test public void testValidateFormula() { `
However, when I run the above code, my assertTrue is false . I guess I did something wrong in my layout setup. How would I test the above method by simulating the return value of methodThatCalculatAFormula without actually calling it.
source share