AssertThat错误:无法访问路径(找不到java.nio.file.Path)

时间:2017-07-14 10:25:05

标签: java android junit robolectric assertj

我想使用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());
}

}

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

1 个答案:

答案 0 :(得分:1)

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

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

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

根据AssertJ documentation