Reputation: 25
I want to use Robolectric for Unit Testing but I am trying a simple test with robolectric and I am stuck at the beginning. I followed the manual, I did the same with the examples and even other posts couldn't help me. Every time I get the error message: cannot access path. class file for java.nio.file.Path not found.
My build.gradle is:
testCompile "org.robolectric:robolectric:3.3.2"
testCompile "org.robolectric:shadows-support-v4:3.3.2"
testCompile 'junit:junit:4.12'
My Test class is:
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());
}
}
But every settings doesn't work. Any help is much appreciated, thanks for any help.
Upvotes: 0
Views: 963
Reputation: 64959
From the comments, the solution was to replace the line
import static org.assertj.core.api.Assertions.assertThat;
with
import static org.assertj.core.api.Java6Assertions.assertThat;
as per the AssertJ documentation.
Upvotes: 1