Android单元测试工具robolectric

发表于:2014-4-01 11:17

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:孔庆云kevin    来源:51Testing软件测试网采编

分享:
  编写第一个测试用例
  右键EmmageeTest工程下的test文件夹,新建一个测试类
package com.netease.emmagee.test;
import org.junit.Assert;
import org.junit.Test;
import org.robolectric.RobolectricTestRunner;
import org.junit.runner.RunWith;
import com.netease.qa.emmagee.R;
import com.netease.qa.emmagee.activity.MainPageActivity;
@RunWith(RobolectricTestRunner.class)
public class MainPageActivityTest {
@Test
public void beginingTest() throws Exception {
String hello = new MainPageActivity().getResources().getString(R.string.bg);
Assert.assertEquals(hello, "开始测试");
}
}
  Eclipse中运行第一个测试用例
  如果需要通过Eclipse中运行测试用例,必须经过以下配置
  右键EmmageeTest -> Run as -> Run configurations
  双击 Junit
  选择Run all tests in the selected project, package or source folder,点击 search选择 EmmageeTest
  TestRunner选择Junit4
  点击下方的Multiple launchers available Select one…,选择Eclipse Junit Launcher
  点击“Arguments” tab,在“Working directory:”中点击“Other”,点击“Workspace”,选择Emmagee工程(不是EmmageeTest工程)
  点击ok完成设置
  设置完成后右键MainPageActivityTest -> Run as -> Junit Test
22/2<12
重磅发布,2022软件测试行业现状调查报告~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计

法律顾问:上海漕溪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号