import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.helloAndroid.Books; import com.helloAndroid.HelloAndroid; import com.helloAndroid.R; import android.R.xml; import android.test.ActivityInstrumentationTestCase2; import android.widget.ListView; import android.widget.SimpleAdapter; public class Junit3 extends ActivityInstrumentationTestCase2<Books> {
ListView listView; Books books; public Junit3() { super("com.helloAndroid.HelloAndroid" ,Books.class); // TODO Auto-generated constructor stub } protected void setUp() throws Exception { super.setUp(); books = this.getActivity(); }
//添加testPreconditions()方法,检查初始化环境,只执行一次 public void testPreconditions() { //assertNotNull(integer); } //添加单元测试 public void testText() { //assertEquals(resourceString,(String)mView.getText()); List<Map<String, Object>> resourceName = new ArrayList<Map<String,Object>>(); Map<String ,Object> map = new HashMap<String, Object>(); map.put("line1", "测试Junit"); map.put("img", R.drawable.weikexue); resourceName.add(map); //listView = (ListView)books.findViewById(com.helloAndroid.R.id.l) SimpleAdapter notes = new SimpleAdapter( books, resourceName, R.layout.rows, new String[]{"line1" ,"img"}, new int[]{R.id.text1, R.id.img}); //books.setListAdapter(notes); } } |