0

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.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
mischi
  • 25
  • 9
  • Is the use of java.nio.file.Path in your code or in a library? Please edit your question to include a full stacktrace if you have one. Also, which version of Android are you targeting? Note that java.nio.file.Path isn't part of Android until API version 26 (O, which is still in preview): https://developer.android.com/reference/java/nio/file/Path.html – Luke Woodward Jul 14 '17 at 11:46
  • it comes along with the use of assertThat from org.assertj.core.api.Assertions. So I assume the use is in a library. If I comment out the assertThat(true) part, it compiles. – mischi Jul 14 '17 at 12:00
  • 1
    The [AssertJ documentation](http://joel-costigliola.github.io/assertj/assertj-core.html) says 'Use the Java6Assertions entry point on Android', for AssertJ 2 or 3, which I assume you are using. Have you tried doing that? – Luke Woodward Jul 15 '17 at 11:08
  • Thanks for pointing me into the right direction. The entry Point was wrong. Thanks again. – mischi Jul 17 '17 at 12:33

1 Answers1

1

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.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104