首页 > 其他分享 >单元测试1(Androidf)

单元测试1(Androidf)

时间:2023-02-06 18:35:18浏览次数:46  
标签:MathUtils Log 单元测试 test Androidf android com public


步骤:

incrment)。  --incrment

MathUtils类中的main方法直接测试,会有异常,如下:

If you would like to submit a bug report, please visit:
​​​     http://java.sun.com/webapps/bugreport/crash.jsp#​

       2.测试incrment方法,Test类需要继承AndroidTestCase

此时不能测试,测试会有如下错误:

JunitTest does not specify a android.test.InstrumentationTestRunner instrumentation or 

       3.在清单文件中指定测试信息和要测试的包, 指定引用的测试包 

     


1.

<span style="font-size:14px;">package com.ithema28.junittest.test;

import com.ithema28.junittest.utlis.MathUtils;

import android.test.AndroidTestCase;

public class Test extends AndroidTestCase{


public void test(){
// System.out.println("test dsa ");

int result = MathUtils.incrment(9, 10);
//断言 ,断定某一个对象就是某一个值
assertEquals(19, result);
}
/*
JunitTest does not specify a android.test.InstrumentationTestRunner instrumentation or
does not declare uses-library android.test.runner in its AndroidManifest.xml
*/

}
</span>

2.


<span style="font-size:14px;">package com.ithema28.junittest.utlis;

import android.util.Log;

public class MathUtils {


/**
* 加法运算
* */
public static int incrment(int x,int y){
/*
这几个BUG依次增强
*/
Log.v("MathUtils", "黑色:" + x + " + " + y + " = " + (x+y));
Log.d("MathUtils","蓝色:" + x + " + " + y + " = " + (x+y));
Log.i("MathUtils", "绿色:" +x + " + " + y + " = " + (x+y));
Log.w("MathUtils","黄色:" + x + " + " + y + " = " + (x+y));
Log.e("MathUtils","红色:" + x + " + " + y + " = " + (x+y));

return x+y;
}
/*
这样测试不对
If you would like to submit a bug report, please visit:
http://java.sun.com/webapps/bugreport/crash.jsp#
* */
/*
public static void main(String[] args) {

MathUtils m = new MathUtils();
int result = m.incrment(1,2);
System.out.println(result);
}
*/

}
</span>


3.

<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ithema28.junittest"
android:versionCode="1"
android:versionName="1.0" >


<!-- 指定测试信息和要测试的包 -->
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.ithema28.junittest"></instrumentation>

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<!-- 指定引用的测试包 -->
<uses-library android:name="android.test.runner"/>


<activity
android:name=".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>
</application>

</manifest>




标签:MathUtils,Log,单元测试,test,Androidf,android,com,public
From: https://blog.51cto.com/u_15955675/6040207

相关文章

  • 单元测试2(android)
    在另一个Junit中测试工程的某一个方法。在Junit中的测试(JunitTest)MathUtils类中的incrment方法这时候,清单文件已经帮你配置好了<?xmlversion="1.0"encoding="utf-8"?><......
  • 若依微服务版(SpringBoot/SpringCloudAlibaba)中在单个服务模块中进行单元测试
    场景若依微服务版手把手教你本地搭建环境并运行前后端项目:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/109363303在上面的基础上需要在某个服务模块中......
  • 单元测试内容及不测试的内容
    PS:单元测试是程序编写人员必备的一些基本素质,所有的程序人员应该把其作为自己工作内容的一部分,白盒测试人员应该加强对程序编写人员相关单元测试理论和实践经验的培训和......
  • 单元测试的回滚
    一般在单测上加上注解:@Transactional@Rollback就可以对单测的数据库操作回滚。但是如果配了多数据源,对于非主数据源的数据库操作,这种办法不会起作用。这时候需要对​​......
  • 单元测试|Unittest setup前置初始化和teardown后置操作
    Unittestsetup前置初始化和teardown后置操作针对类中每个函数执行时进行前置后置的操作setUp(self):测试前的初始化操作tearDown(self):测试后的操作代码示例:importunittest......
  • 单元测试中获取Method参数为 arg0
    for(Parameterparameter:parameters){if(!parameter.isNamePresent()){System.out.println("NON");continue;}Stringname=paramete......
  • cra react18 ts 自定义hooks 单元测试
    首先创建cra项目如果报错说最新的create-react-app版本是5.x,而你的是4.x的话需要先卸载,再重新安装sudonpmuninstall-gcreate-react-appsudonpminst......
  • 单元测试|unittest生成测试报告
    unittest生成测试报告测试报告为测试结果的统计即展示,是自动化测试不可或缺的一部分,利用unittest可以生成测试报告。使用第三方HTMLTestRunner执行测试用例集,生成网页版......
  • 0141-Go-单元测试
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/testing-and-benchmarking目标使用Go语言进行测试。示例packagemainimport("fmt"......
  • SpringBoot单元测试:@SpringBootTest
    接上一篇:SpringBoot整合SSM添加依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId......