我正在尝试使用Robolectric设置测试以单击此存储库中的菜单按钮.基本的Robolectric测试将运行,但我无法使用资源运行任何项目特定的测试,因为它说它无法找到我的AndroidManifest.xml.运行后../gradlew clean check,这是Robolectric html文件的标准输出:
WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only.
To remove this warning, annotate your test class with @Config(manifest=Config.NONE).
我发现这些说明表明我应该创建一个org.robolectric.Config.properties文件,但我不知道该把它放到哪里.我几乎到处都试过,尽管移动了文件,但错误信息中的路径始终与上面相同(./AndroidManifest.xml).这让我觉得构建过程从未获取文件中的设置org.robolectric.Config.properties.
我也尝试了@Config(manifest ="")指令,但这给了我一个cannot find symbol错误.如果我将AndroidManifest.xml移动到我的项目目录中,那么我得到一个错误,它无法找到路径./res/values,我也无法解决.有任何想法吗?
更新1
谢谢欧根,我现在用@RunWith(RobolectricGradleTestRunner.class)而不是@RunWith(RobolectricTestRunner).
现在我得到了一个不同的错误,仍然发生在我的BasicTest.java的同一行
KeywordList keywordList = Robolectric.buildActivity(KeywordList.class).create().get();
Run Code Online (Sandbox Code Playgroud)
以下是Robolectric测试报告中标准错误,标准输出和"失败测试"选项卡的结果:
注意:我也尝试用最新的Robolectric更新,robolectric-2.2-SNAPSHOT.jar构建的jar替换,但仍然出错.
标准错误
WARNING: no system properties value for ro.build.date.utc
标准输出
DEBUG: Loading resources for net.frontlinesms.android from ~/workspace-studio/frontlinesms-for-android/FrontlineSMS/build/res/all/debug...
DEBUG: Loading …Run Code Online (Sandbox Code Playgroud) 我正在努力让Robolectric测试并在我们当前的项目中工作,而且没有太多运气.我的偏好是让它们在Android Studio 1.1.0+中运行.这是我的项目结构:

这是我的测试:
import android.widget.Button;
import com.mycompany.android.app.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertNotNull;
@Config(manifest = "AndroidManifest.xml")
@RunWith(RobolectricTestRunner.class)
public class SplashActivityTest {
private SplashActivity splashActivity;
@Before
public void setup() {
splashActivity = Robolectric.buildActivity(SplashActivity.class).create().start().resume().get();
}
@Test
public void shouldNotBeNull() {
Button signUpButton = (Button) splashActivity.findViewById(R.id.sign_up_button);
assertNotNull(signUpButton);
Button loginButton = (Button) splashActivity.findViewById(R.id.login_button);
assertNotNull(loginButton);
}
}
Run Code Online (Sandbox Code Playgroud)
无论我做什么来尝试通过更改清单的路径来让框架找到测试,它都找不到它 - 我得到WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only.消息或 …