编写第一个测试用例
右键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