在实际开发中,开发Android软件的过程需要不断的测试,而使用Junit测试框架,这是正规的Android开发的必用技术,在Junit中可以得到组件,可以模拟发送事件和检测程序处理的正确性.(编写单元测试代码)选择要测试的方法.
package com.glsite.junit;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.glsite.junit", appContext.getPackageName());
assertEquals(4, 5);
}
}