标签:system .com 目录 private type add end 功能 cat
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
int sum = 2 + 2;
System.out.println("结果为:" + sum);
assertEquals(4, sum);
}
}
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
//方法名必须以test开头,并且方法不能带参数
public void testSimple() {
int width = getScreenWidth(getContext());
Log.i("bqt", "屏幕宽:" + width);
Toast.makeText(getContext(), "屏幕宽:" + width, Toast.LENGTH_SHORT).show();
//assertEquals(4, 2 + 2);//可以没有声明语句
}
/**
* 获取屏幕宽
*/
private int getScreenWidth(Context context) {
DisplayMetrics metric = new DisplayMetrics();
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metric);
return metric.widthPixels;
}
}
标签:system .com 目录 private type add end 功能 cat
原文地址:http://www.cnblogs.com/baiqiantao/p/b4a1112337ed5d2717b004950124434b.html