Skip to content

Commit

Permalink
简化接入步骤,支持一键屏蔽
Browse files Browse the repository at this point in the history
  • Loading branch information
“gujinjie” committed Jun 19, 2017
1 parent ba10158 commit 2b62a13
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# JacocoTestHelper
Jacoco手工测试代码覆盖率的辅助工具

#Usage

1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
apply from: 'jacoco.gradle'

android {
Expand Down
25 changes: 15 additions & 10 deletions app/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
apply plugin: 'jacoco'
/**
* 手动测试代码覆盖率
* Useage:
*
* 1、可以直接编译运行或者安装应用
* 2、./gradlew jacocoInit 初始化
* 3、开始测试,测试结束后点击生成报告将ec文件pull到本地项目 PROJECT_PATH 路径中,具体命令可查看日志Loge<Pull>
* PROJECT_PATH '项目路径/app/build/' + 'outputs/code-coverage/'
* 4、./gradlew jacocoTestReport 然后到 /app/build/reports里查看相关报告
*
*/

//Java源码路径
def coverageSourceDirs = [
'../app/src/main/java'
Expand All @@ -8,17 +21,9 @@ jacoco {
toolVersion = "0.7.9"
}

//以下配置均已配置好,原则上不需要有任何修改即可正常使用

/**
* 手动测试代码覆盖率
* Useage:
*
* 1、可以直接编译运行或者安装应用
* 2、./gradlew jacocoInit 初始化
* 3、开始测试,测试结束后点击生成报告将ec文件pull到本地项目 PROJECT_PATH 路径中,具体命令可查看日志Loge<Pull>
* PROJECT_PATH '项目路径/app/build/' + 'outputs/code-coverage/'
* 4、./gradlew jacocoTestReport 然后到 /app/build/reports里查看相关报告
*/
//生成报告task
task jacocoTestReport(type: JacocoReport) {
group = "JacocoReport"
description = "Generate Jacoco coverage reports after running tests."
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jaygoo.jacocotest">
<!--必须的权限-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> <!-- To retrieve the account name (email) as part of sign-in: -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -16,7 +15,6 @@
<activity android:name=".TestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}

Expand Down
15 changes: 11 additions & 4 deletions library/src/main/java/jaygoo/jacocohelper/JacocoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
import java.io.IOException;
import java.io.OutputStream;


/**
* jacoco收集覆盖率统计工具
* ================================================
* 作 者:JayGoo
* 版 本:
* 创建日期:2017/6/16
* 描 述: jacoco收集覆盖率统计辅助类
* ================================================
*/

public class JacocoHelper {

//ec文件的路径
Expand All @@ -22,11 +27,11 @@ public class JacocoHelper {

/**
* 初始化
* @param projectPath '项目路径/app/build/' + 'outputs/code-coverage/'
* @param projectPath '项目路径' + '/app/build/outputs/code-coverage/'
* @param isDebug 是否打开log
*/
public static void init(String projectPath, boolean isDebug){
PROJECT_PATH = projectPath;
PROJECT_PATH = projectPath + "/app/build/outputs/code-coverage/";
LogUtils.setDebug(isDebug);
}

Expand All @@ -36,6 +41,7 @@ public static void init(String projectPath, boolean isDebug){
* @param isNew 是否重新创建ec文件
*/
public static void generateEcFile(boolean isNew) {
if (!LogUtils.isDebug())return;
OutputStream out = null;
File mCoverageFilePath = new File(DEFAULT_COVERAGE_FILE_PATH);
try {
Expand Down Expand Up @@ -64,6 +70,7 @@ public static void generateEcFile(boolean isNew) {
e.printStackTrace();
}
}
LogUtils.d(getAdbPullCmd());
}


Expand Down
7 changes: 7 additions & 0 deletions library/src/main/java/jaygoo/jacocohelper/LogUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package jaygoo.jacocohelper;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

/**
* ================================================
Expand All @@ -19,9 +21,14 @@ public static void setDebug(boolean debug){
isDebug = debug;
}

public static boolean isDebug(){
return isDebug;
}

public static void d(String msg){
if (isDebug){
Log.d(TAG,msg);
}
}

}

0 comments on commit 2b62a13

Please sign in to comment.