【发布时间】:2013-01-22 21:53:14
【问题描述】:
我正在尝试运行在可执行 .jar 文件中启动的 Robolectric 测试。 Robolectric requires 您将 File 传递给其构造函数,其目录包含 AndroidManifest.xml 文件。我的 AndroidManifest.xml 文件位于我的 .jar 文件的根目录中,并且测试运行程序位于类似 com.some.package 的包中。我怎样才能做到这一点?
我尝试了以下方法:
public class CustomTestRunner extends RobolectricTestRunner {
public CustomTestRunner(Class testClass) throws InitializationError, URISyntaxException {
super(testClass, new File(CustomTestRunner.class.getResource("/AndroidManifest.xml").getPath().replace("AndroidManifest.xml", "")));
}
}
哪个不起作用,当它运行 Robolectric 时抱怨,我得到这个 FileNotFoundException:
java.io.FileNotFoundException: /Users/christopherperry/Desktop/file:/Users/christopherperry/Desktop/my-executable-jar.jar!/AndroidManifest.xml 未找到或没有文件;它应该指向您项目的 AndroidManifest.xml 位于 com.xtremelabs.robolectric.RobolectricConfig.validate(RobolectricConfig.java:73) 在 com.xtremelabs.robolectric.RobolectricTestRunner.createResourceLoader(RobolectricTestRunner.java:602)
我不明白,因为 AndroidManifest.xml 文件位于 jar 文件的根目录中,从错误消息来看,这似乎是它正在寻找的位置。
【问题讨论】:
标签: java file executable-jar robolectric