For example, fragment A
String readSource(String file);
fragment B
String readSource(InputStream in);
So, if we define the interface as A, then we can only create the file for testing. But after a while it will be difficult to manage the test files. Therefore, using interface B, it will simplify testing. I just need to create a fake InputStream and then check if the method returns the desired result. But we must handle an IOException before we call this method every time.
source share