Skip to content

Adding a coverage report for android #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/codecov-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# uploading codecov report

name: Upload Codecov Report

on: [push, pull_request]

jobs:
test:
runs-on: macOS-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: 15.0.2
- name: Build and run unit tests
run: |
./gradlew build jacocoTestReport
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
42 changes: 29 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ buildscript {
ext.kotlin_version= '1.8.20'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath('com.mxalbert.gradle:jacoco-android:0.2.1')
}
repositories {
mavenCentral()
@@ -12,24 +13,19 @@ buildscript {

plugins {
id "io.sentry.android.gradle" version "4.10.0"
id 'com.android.application'
id 'kotlin-android'
id 'com.ydq.android.gradle.native-aar.import'
id 'jacoco'
id 'com.mxalbert.gradle.jacoco-android' version '0.2.1'
}

apply plugin: 'com.android.application'
apply plugin: 'com.ydq.android.gradle.native-aar.import'
apply plugin: 'io.sentry.android.gradle'
apply plugin: 'kotlin-android'
//apply plugin: 'fullstory'

//fullstory {
// org 'QNEN8'
// enabledVariants 'all'
// logLevel 'off'
//}

task wrapper(type: org.gradle.api.tasks.wrapper.Wrapper) {
gradleVersion = '7.0'
}

android {
compileSdkVersion 31

@@ -45,6 +41,7 @@ android {
versionCode 46
versionName "2.11.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments.add(0, "-DANDROID_STL=c++_static")
@@ -83,8 +80,6 @@ android {
lintOptions {
abortOnError false
}
ndkVersion '21.3.6528147'

}

dependencies {
@@ -96,7 +91,7 @@ dependencies {
implementation 'androidx.navigation:navigation-ui:2.5.3'
implementation 'com.android.support:support-core-utils:28.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'junit:junit:4.12'
implementation 'junit:junit:4.13.2'
implementation 'com.google.code.gson:gson:2.10.1'
def fragment_version = "1.5.6"
// Java language implementation
@@ -111,6 +106,27 @@ dependencies {
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

testImplementation 'org.jetbrains:annotations:23.0.0'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.8.0'
testImplementation 'org.robolectric:robolectric:4.10.3'
testImplementation 'org.mockito.kotlin:mockito-kotlin:4.1.0'
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'androidx.test.ext:junit:1.1.3'
testImplementation 'androidx.test:runner:1.4.0'

// JUnit 5 dependencies
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

jacoco {
toolVersion = "0.8.10"
}

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true // is this necessary
jacoco.excludes = ['jdk.internal.*'] // is this necessary
}

sentry {
Original file line number Diff line number Diff line change
@@ -206,7 +206,7 @@ public void onItemClick(StoreItem storeItem) {
adapter.notifyDataSetChanged();
}

private void processGetToolsResponse(String body) {
void processGetToolsResponse(String body) {

JSONObject jsonObject = null;
try {
@@ -271,7 +271,7 @@ private void processProducts() {
}
}

private int getIterator(int n) {
int getIterator(int n) {
if (n <= 0) {
return 0;
}
@@ -281,7 +281,7 @@ private int getIterator(int n) {
return getIterator(n-1) + getIterator(n-2);
}

private String getEmpowerPlantDomain() {
String getEmpowerPlantDomain() {
String domain = null;
try {
final ApplicationInfo appInfo = getActivity().getApplicationContext().getPackageManager().getApplicationInfo(getActivity().getApplicationContext().getPackageName(),
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.vu.android.empowerplant;

import android.content.Context;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.when;

public class MainFragmentTest {

@Mock
Context mockContext;

private MainFragment mainFragment;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mainFragment = new MainFragment();
mainFragment.onAttach(mockContext);
}

@Test
public void testGetEmpowerPlantDomain() {
String domain = "https://application-monitoring-flask-dot-sales-engineering-sf.appspot.com";
when(mockContext.getString(anyInt())).thenReturn(domain);

String result = mainFragment.getEmpowerPlantDomain();

assertEquals("", "");
}

@Test
public void testGetIterator() {
assertEquals(0, mainFragment.getIterator(0));
}
}
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -9,8 +9,9 @@ buildscript {
maven { url "https://maven.fullstory.com" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.ydq.android.gradle.build.tool:nativeBundle:1.0.7'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
classpath "io.github.howardpang:androidNativeBundle:1.1.4"
classpath 'com.fullstory:gradle-plugin-local:1.12.1'
}
}
@@ -19,6 +20,7 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Thu Aug 01 11:14:39 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading