这些天我正在为 android 编写一个演示应用程序,使用 robolectric for TA。我可以运行该项目,但是当我添加测试时,它会显示如下错误:
error message="java.lang.RuntimeException: no such directory /Users/majie/Downloads/android-sdk-macosx/platforms/android-9/data/res/values" type="java.lang.RuntimeException">java.lang.RuntimeException: java.lang.RuntimeException: no such directory /Users/majie/Downloads/android-sdk-macosx/platforms/android-9/data/res/values
at com.xtremelabs.robolectric.res.ResourceLoader.init(ResourceLoader.java:93)
at com.xtremelabs.robolectric.res.ResourceLoader.inflateView(ResourceLoader.java:261)
at com.xtremelabs.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:43)
at com.xtremelabs.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:48)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at com.xtremelabs.robolectric.shadows.ShadowActivity.setContentView(ShadowActivity.java:73)
at android.app.Activity.setContentView(Activity.java)
at com.cisco.jabberim.ui.WelcomeActivity.onCreate(WelcomeActivity.java:21)
at Test.FTE.WelcomeActivityTest.setUp(WelcomeActivityTest.java:28)
测试文件如下:
@RunWith(RobolectricTestRunner.class)
public class WelcomeActivityTest {
private WelcomeActivity mActivity;
private TextView text;
@Before
public void setUp(){
mActivity = new WelcomeActivity();
mActivity.onCreate(null);
text = (TextView) mActivity.findViewById(R.id.welcome);
}
@Test
public void textIsNotNull(){
String str = text.getText().toString();
assertNotNull(str);
}
}
pom.xml 是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven- v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>im</groupId>
<artifactId>Im</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>IM demo</name>
<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>3.0_r2</version>
<scope>provided</scope>
</dependency>
<!-- Make sure this is below the android dependencies -->
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.0-RC1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<!-- See http://code.google.com/p/maven-android-plugin/ -->
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<sdk>
<!-- platform or api level (api level 8 = platform 2.2)-->
<platform>11</platform>
</sdk>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
我真的不知道如何解决它。我不知道为什么奇怪的路径是“/Users/majie/Downloads/android-sdk-macosx/platforms/android-9/data/res/values”。我不知道在哪里设置它或如何使它正确。