android - Robolectric 获取Context问题.
PHPz
PHPz 2017-04-17 18:00:24
0
0
588

我使用了Robolectric在做单元测测试,但是怎么获取Context呢?
这是我的代码

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class NiaoSuanTest {

    @Test
    public void testNiaoSuan() {

        MonitorEngine engine = new MonitorEngine(context);
        String residentId = (String) SPUtil.get(context, ResidentInfo.ID, "");
        String gender = (String) SPUtil.get(context, ResidentInfo.GENDER, "1");
        Date date = TimeUtil.paresDateByStr((String) SPUtil.get(context, ResidentInfo.BIRTHDAY, ""));


        Map<Integer, String> param = new HashMap<>();
        param.put(1, "5.5");

        NewMonitorResult monitorResult = engine.monitorProcessByManualdrive("683edfb67a6311e69f52d017c2939671", param, residentId, Integer.parseInt(gender), date, null);
        if (monitorResult != null) {
            Map<String, Object> params = new HashMap<>();
            params.put("data", monitorResult);
            Zcareze.javascript("DeviceMonitor", params);
        } else {
            Zcareze.javascript("DeviceMonitor", null);
        }
    }
}

我使用了: Context applicationContext = getApplicationContext()
还有 Context context = new MockContext();
都不管用. 求大神帮忙! 谢谢.

PHPz
PHPz

学习是最好的投资!

Antworte allen(0)
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage