Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的ServiceTestCase的getSystemContext()返回null_Java_Android_Unit Testing_Junit_Servicetestcase - Fatal编程技术网

Java 我的ServiceTestCase的getSystemContext()返回null

Java 我的ServiceTestCase的getSystemContext()返回null,java,android,unit-testing,junit,servicetestcase,Java,Android,Unit Testing,Junit,Servicetestcase,我对下面的代码进行了测试,但是我得到了一个NullpointerException,因为getSystemContext()返回null。 我的项目如下所示: ~/trunk/src/<packages>/<classes> ~/trunk/test/<packages/<testclasses> ~/trunk/<static android dirs> ~/trunk/AndroidManifest.xml ~/trunk/src//

我对下面的代码进行了测试,但是我得到了一个NullpointerException,因为getSystemContext()返回null。 我的项目如下所示:

~/trunk/src/<packages>/<classes>
~/trunk/test/<packages/<testclasses>
~/trunk/<static android dirs>
~/trunk/AndroidManifest.xml
~/trunk/src//

~/trunk/test/您是使用Robolectric还是Android测试项目编写测试?测试在maven构建过程中运行。为了防止存根类的堆栈跟踪,我使用Roboelectric来运行单元测试。你找到解决这个问题的方法了吗?我面临着同样的问题。你是使用Robolectric还是Android测试项目编写测试?测试在maven构建过程中运行。为了防止存根类的堆栈跟踪,我使用Roboelectric来运行单元测试。你找到解决这个问题的方法了吗?我也面临同样的问题。
    @RunWith(RobolectricTestRunner.class)
    public class MyServiceTest extends ServiceTestCase<MyService> {


    public MyServiceTest() {
       super(MyService.class);
    }

    @Test
    public void testStartable() {
       Context mockContext = getSystemContext();
       Log.d("testStartable", "testContext " + mockContext.getClass().getCanonicalName());
       Intent startIntent = new Intent();
       startIntent.setClass(mockContext, MyService.class);
       mockContext.startService(startIntent);
       assertNotNull(getService());
    }
   }