安卓测试

准备工作

导入junit的jar包的方法:新建lib目录,将两个jar包(junit-4.11.jar和hamcrest-core-1.3.jar)放入,然后,选中两个jar包,右键Add as Library

测试

安卓测试 log日志必须打开avd才能看得到,而且要运行在主程序
java测试,使用sout就能看到

安卓测试

package com.example.androidtest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import org.junit.Test;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
test test=new test();
test.testTest();
    }
    public class test {
        private static final String TAG="test1";
        public Random random = new Random();
        @Test
        public void testTest(){
            int red = random.nextInt(256) / 1;
            int green = random.nextInt(256) / 1;
            int blue = random.nextInt(256) / 1;
            //Toast.makeText(MainActivity.this, "red"+"\n"+red+"greed"+"\n"+green+"blue"+"\n"+blue, Toast.LENGTH_SHORT).show();
          //  System.out.println("red"+red+"greed"+green+"blue"+blue);
            Log.d(TAG, "red"+red+"\n"+"greed"+green+"\n"+"blue"+blue);

        }
    }

}

java测试

a.java

package com.example.androidtest;

import android.util.Log;

import org.junit.Test;

import java.util.Random;

public class a {
        private static final String TAG="test1";
        public Random random = new Random();
        public void testTest(){
            int red = random.nextInt(256) / 1;
            int green = random.nextInt(256) / 1;
            int blue = random.nextInt(256) / 1;
            //Toast.makeText(MainActivity.this, "red"+"\n"+red+"greed"+"\n"+green+"blue"+"\n"+blue, Toast.LENGTH_SHORT).show();
            //  System.out.println("red"+red+"greed"+green+"blue"+blue);
            Log.d(TAG, "red"+red+"\n"+"greed"+green+"\n"+"blue"+blue);
            System.out.println("red"+red+"\n"+"greed"+green+"\n"+"blue"+blue);
        }
    }

testa.java

package com.example.androidtest;

import org.junit.Test;


public class testa {
    @Test
    public void testa()
    {
        a a1 = new a();
        a1.testTest();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值