I am learning how to unit-testing in android studio. As shown below, I have a method called "isValidUrl" and in the testing section below, I coded the testing of that method using Mockito, but the test always fails.
Can you please help and guild me how to test this method?
code
public boolean isValidUrl(String url) {
return (url != null && !url.equals("")) ? true : false;
}
testing:
public class ValidationTest {
@Mock
private Context mCtx = null;
@Before
public void setUp() throws Exception {
mCtx = Mockito.mock(Context.class);
Assert.assertNotNull("Context is not null", mCtx);
}
@Test
public void isValidUrl() throws Exception {
Validation validation = new Validation(mCtx);
String url = null;
Mockito.when(validation.isValidUrl(url)).thenReturn(false);
}
}