首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >机器人电气测试

机器人电气测试
EN

Stack Overflow用户
提问于 2016-06-30 16:43:21
回答 1查看 53关注 0票数 0

我以前从来没有使用过任何类型的JUnit,所以从我搜索到的结果中,有一个很好的工具叫做roboelectric

我试着运行一个简单的测试,如他们的网站所示,但是assertThat()和shadowOf()不被识别。

下面是测试结果

代码语言:javascript
复制
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class MainActivityTest {

@Test
public void clickingLogin_shouldStartLoginActivity() {
    MainActivity activity = Robolectric.setupActivity(MainActivity.class);
    activity.findViewById(R.id.login).performClick();

    Intent expectedIntent = new Intent(activity, LoginActivity.class);
    //This line doesn't work.         
    assertThat(shadowOf(activity).getNextStartedActivity()).
    isEqualTo(expectedIntent);

  }
 }

这就是我在gradle中设置Roboelectric的方法。

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
    applicationId "testing.theo.robotutorial"
    minSdkVersion 14
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),   
'proguard-rules.pro'
    }
   }
 }

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:24.0.0'
  testCompile "org.robolectric:robolectric:3.0"


 }

有什么想法吗?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-02-14 15:30:14

替换为以下断言将起作用。

代码语言:javascript
复制
assertTrue(shadowOf(activity).getNextStartedActivity().filterEquals(expectedIntent));

您可以参考Roboelectric github issue #2627中的answer by Hoisie了解详细信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38118068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档