0

我想使用 Robolectric 进行单元测试,但我正在尝试使用 robolectric 进行简单测试,但我一开始就卡住了。我按照手册进行操作,对示例进行了同样的操作,甚至其他帖子也无济于事。每次我收到错误消息:无法访问路径。找不到 java.nio.file.Path 的类文件。

我的 build.gradle 是:

testCompile "org.robolectric:robolectric:3.3.2"
testCompile "org.robolectric:shadows-support-v4:3.3.2"
testCompile 'junit:junit:4.12'

我的测试课是:

package com.dev.mann.chronoly;
import android.support.v7.widget.RecyclerView;
import org.junit.runner.RunWith;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowToast;
import org.robolectric.shadows.support.v4.SupportFragmentTestUtil;
import static 
org.robolectric.shadows.support.v4.SupportFragmentTestUtil.startFragment;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class CrngyMasterFragmentTestClass{
private CrngyMasterFragment mFrag;
RecyclerView mMainRecyclerView;
MainActivity activity;

@Before
public void setup() {
   activity = Robolectric.buildActivity(MainActivity.class).create().start().visible().get();
   //SupportFragmentTestUtil.startVisibleFragment(mFrag, MainActivity.class, R.id.master_frag_container);
}


@Test
public void checkEmptyFragments() throws Exception {
    //SupportFragmentTestUtil.startVisibleFragment(mFrag, AppCompatActivity.class, R.id.master_frag_container);
    assertThat(true);
    // check the recyclerview items
    //RecyclerView recyclerView = (RecyclerView) mFrag.getActivity().findViewById(R.id.mainRecyclerView);
    //assertThat(recyclerView.isShown());
}

}

但是每个设置都不起作用。非常感谢任何帮助,感谢您的帮助。

4

1 回答 1

1

从评论中,解决方案是替换该行

import static org.assertj.core.api.Assertions.assertThat;

import static org.assertj.core.api.Java6Assertions.assertThat;

根据AssertJ 文档

于 2017-07-17T19:28:52.570 回答