- 浏览: 516649 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
tangyunliang:
大哥你太历害了谢谢
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
u013015029:
LZ,请问下,在// 添加消息到聊天窗口 , 这里获取Ed ...
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
endual:
怎么保持会话,我搞不懂啊
Android基于XMPP Smack Openfire开发IM【一】登录openfire服务器 -
donala_zq:
显示:[2013-11-30 11:50:36 - Andro ...
android-----------新浪微博 -
donala_zq:
哥,运行不了啊
android-----------新浪微博
运行效果图:
[img]
[/img]
项目结构图:
[img]
[/img]
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="fill_parent"> <TextView android:id="@+id/ResultView" android:text="測試結果" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/BarView" android:text="barView" android:layout_marginTop="50dip" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/MessageView" android:text="message" android:layout_marginTop="50dip" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/LunchButton" android:text="button" android:layout_marginTop="50dip" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
TestMath
要测试的两个地方
package com.example.junitandroidtest; import android.test.AndroidTestCase; public class TestMath extends AndroidTestCase{ private int i1; private int i2; static final String LOG_TAG = "MathTest"; @Override protected void setUp() throws Exception { i1 = 2; i2 = 3; } public void testAdd() { assertTrue("testAdd failed", ((i1 + i2) == 6)); } public void testDec() { assertTrue("testDec failed", ((i2 - i1) == 0)); } @Override protected void tearDown() throws Exception { super.tearDown(); } @Override public void testAndroidTestCaseSetupProperly() { super.testAndroidTestCaseSetupProperly(); //Log.d( LOG_TAG, "testAndroidTestCaseSetupProperly" ); } }
ExampleSuite
package com.example.junitandroidtest; import junit.framework.TestSuite; public class ExampleSuite extends TestSuite { public ExampleSuite() { addTestSuite(TestMath.class); } }
MainActivity.java
package com.example.junitandroidtest; import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestListener; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.graphics.Color; import android.test.AndroidTestRunner; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private TextView resultView; private TextView barView; private TextView messageView; private Thread testRunnerThread; private static final int SHOW_RESULT = 0; private static final int ERROR_FIND = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); resultView = (TextView) findViewById(R.id.ResultView); barView = (TextView) findViewById(R.id.BarView); messageView = (TextView) findViewById(R.id.MessageView); Button lunch = (Button) findViewById(R.id.LunchButton); lunch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startTest(); } }); } private void showMessage(String message) { hander.sendMessage(hander.obtainMessage(ERROR_FIND, message)); } private void showResult(String text) { hander.sendMessage(hander.obtainMessage(SHOW_RESULT, text)); } private synchronized void startTest() { if (testRunnerThread != null && testRunnerThread.isAlive()) { testRunnerThread = null; } if (testRunnerThread == null) { testRunnerThread = new Thread(new TestRunner(this)); testRunnerThread.start(); } else { Toast.makeText(this, "Test is still running", Toast.LENGTH_SHORT) .show(); } } public Handler hander = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case SHOW_RESULT: resultView.setText(msg.obj.toString()); break; case ERROR_FIND: messageView.append(msg.obj.toString()); barView.setBackgroundColor(Color.RED); break; default: break; } } }; class TestRunner implements Runnable, TestListener { private Activity parentActivity; private int testCount; private int errorCount; private int failureCount; public TestRunner(Activity parentActivity) { this.parentActivity = parentActivity; } @Override public void run() { testCount = -1; errorCount = 0; failureCount = 0; ExampleSuite suite = new ExampleSuite(); AndroidTestRunner testRunner = new AndroidTestRunner(); testRunner.setTest(suite); testRunner.addTestListener(this); testRunner.setContext(parentActivity); testRunner.runTest(); } @Override public void addError(Test test, Throwable t) { errorCount++; showMessage(t.getMessage() + "\n"); } @Override public void addFailure(Test test, AssertionFailedError t) { failureCount++; showMessage(t.getMessage() + "\n"); } @Override public void endTest(Test test) { showResult(getResult()); } @Override public void startTest(Test test) { testCount++; } private String getResult() { int successCount = testCount - failureCount - errorCount; return "Test:" + testCount + " Success:" + successCount + " Failed:" + failureCount + " Error:" + errorCount; } } }
AndroidManifest.xml
注意里面第26行的添加
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.junitandroidtest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.junitandroidtest.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-library android:name="android.test.runner" /> </application> </manifest>
发表评论
-
Android中如何模拟一次点击(touch)事件
2014-05-06 10:41 0在Android中有时需要模拟某一个View的touch事件, ... -
Android程序Crash时的异常上报
2014-04-28 18:15 0http://blog.csdn.net/singwhatiw ... -
android程序中证书签名校验的方法
2014-04-28 17:58 1898android程序中证书签名校验的方法一 2013-02 ... -
MD5理解错了,哎
2014-03-17 14:14 0MD5只对数据加密是无法解密的,也就是说,你把100加密后,就 ... -
Android 获取网络时间
2014-03-12 11:42 2007Android 获取网络时间 在网上看到的最常见的方式有: ... -
SQLite清空表并将自增列归零
2014-03-05 18:02 1461SQLite清空表并将自增列归零 作者:Zhu Yanfeng ... -
Handler小看一下
2013-11-11 16:42 0android handler调用post方法还是阻塞 su ... -
Frame Animation小看一下
2013-10-12 16:30 713Demo运行效果图: 源码: -
动画小学一下
2013-10-12 16:14 689转自: http://www.eoeandroid.com/f ... -
Android 动画之ScaleAnimation应用详解
2013-10-12 15:49 955===============eoeAndroid社区推荐:= ... -
android开发中的一个工具类
2013-06-19 16:04 0package com.wanpu.login.dialog; ... -
android TextView怎么设置个别字体颜色并换行?
2013-06-20 09:25 1630(1)、TextView 设置个别字体颜色 TextView ... -
Android开发之文件下载,状态时显示下载进度,点击自动安装
2013-05-07 15:38 1361在进行软件升级时,需要进行文件下载,在这里实现自定义的文件下载 ... -
android中的状态保存
2013-04-07 14:21 931package com.zzl.call; import ... -
android动画基础:tween动画
2013-04-06 11:21 1179工程结构图: [img] [/img] 四个动画的xml ... -
面试中遇到的几个问题
2013-06-09 11:56 938SAX与DOM之间的区别 SAX ( ... -
Android获取其他包的Context实例,然后调用它的方法,反射!!!
2013-03-25 10:32 1156Android中有Context的概念,想必大家都知道。Con ... -
Android的内存机制和常见泄漏情形
2013-03-06 16:55 752一、 Android的内存机制 Android的程序由Ja ... -
android开发中的异常小工具
2013-03-04 15:53 860package com.zzl.tools; impor ... -
仿大众点评源码(部分)
2013-06-09 11:54 1827项目中的一些界面: [img] [/img] [img] ...
相关推荐
NULL 博文链接:https://605113068.iteye.com/blog/1725129
springboot整合junit测试用例demo
单元测试框架Junit—— JUnit3.8.1 以及使用JUnit测试的代码demo。
Junit 异常测试demo 适合于java白盒测试初学者。这是一个很好地很简单的例子。
android studio junit测试 activity 对应文章地址 http://blog.csdn.net/qq_28478281/article/details/52891347
junit测试 test txt file
junit测试demo,有纯java和基于ssh的测试类。比较简单,仅供参考。
junit测试测试junit测试测试junit测试测试junit测试测试
Junit测试demo
Myeclipse中的JUnit测试详细
Junit,测试Junit,测试案例使用
junit测试demo,非常简单,大家可以下载试试,非常方便
Junit测试.mp4
Junit测试jar包
Junit 通常用于那些有明确返回值的方法的测试,而无法对返回值是void类型的方法进行测试,因为Junit的assert断言方法只适用于预期值与实际值的比 较,对于void类型的方法,我们无法从它的return语句获得具体的返回值...
Junit单元测试Junit单元测试Junit单元测试Junit单元测试
软件测试JUnit测试框架的使用实验1报告
JUnit测试代码示例,JUnit3的代码示例。
junit3 junit4 api,单元测试的利器
使用Eclipse进行Junit测试,junit类的创建