Issue
I'd like to test (Local unit tests) my app's utils class. I have a problem to test some utils class include android.* class.
java.lang.ClassNotFoundException: android.app.Application
I know that using Roboletric provide me android os class but how to use in my case?
FileUtilsTest.java
@RunWith(RobolectricTestRunner.class)
public class FileUtilsTest {
@Test
public void getVideoDir() throws Exception {
File videoDir = FileUtils.getVideoDir();
//Never null
assertThat("never null", videoDir, notNullValue());
//Check the dir exist
assertThat("Is exist", videoDir.exists(), is(true));
}
....
}
FileUtils.java
public class FileUtils {
private static final String DIR_VIDEO = "/sample/note/video";
public static File getVideoDir() {
File dir = new File(getVideoPath());
dir.mkdirs();
return dir;
}
public static String getVideoPath() {
return Environment.getExternalStorageDirectory().getPath() + DIR_VIDEO;
}
}
Solution
I have figured out by myself.I forgot to add one line below.
@Config(constants = BuildConfig.class)
Answered By - Capotasto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.