我如何测试 Util class include android.os.Environment.getexternalstoragedirectory().getPath()
How do I test Util class include android.os.Environment.getexternalstoragedirectory().getPath()
我想测试(本地单元测试)我的应用程序的实用程序 class。
我在测试一些实用程序时遇到问题 class include android.* class.
java.lang.ClassNotFoundException: android.app.Application
我知道使用 Roboletric 可以为我提供 android os class 但我的情况如何使用?
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;
}
}
我想通了 myself.I 忘了在下面加一行。
@Config(constants = BuildConfig.class)
我想测试(本地单元测试)我的应用程序的实用程序 class。 我在测试一些实用程序时遇到问题 class include android.* class.
java.lang.ClassNotFoundException: android.app.Application
我知道使用 Roboletric 可以为我提供 android os class 但我的情况如何使用?
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;
}
}
我想通了 myself.I 忘了在下面加一行。
@Config(constants = BuildConfig.class)