Skip to content
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

Yuval coverage report #138

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fd65561
adding support for coverage report
Jun 18, 2024
4c35b6a
Create codecov-report.yml
yuval-sentry Jun 18, 2024
4154fd8
Update codecov-report.yml
yuval-sentry Jun 18, 2024
d5f8025
update jacoco config
Jun 18, 2024
ce8158e
Merge branch 'yuval-coverage-report' of github.com:sentry-demos/andro…
Jun 18, 2024
1cb62d4
update codecov config
Jun 18, 2024
e49c5b5
adding tests
Jun 18, 2024
9c8e2ce
Update codecov-report.yml
yuval-sentry Jun 18, 2024
163b2fd
Update codecov-report.yml
yuval-sentry Jun 21, 2024
43dfda5
Update codecov-report.yml
yuval-sentry Jun 21, 2024
d28289e
removing file
Jun 21, 2024
0d9bc76
Merge branch 'yuval-coverage-report' of github.com:sentry-demos/andro…
Jun 21, 2024
58c7809
Update codecov-report.yml
yuval-sentry Jun 21, 2024
9788459
Update codecov-report.yml
yuval-sentry Jun 21, 2024
052bf5f
Update codecov-report.yml
yuval-sentry Jun 21, 2024
b75ede9
Update codecov-report.yml
yuval-sentry Jun 21, 2024
62c0b57
updating build.gradle
Jun 21, 2024
a3cf79c
Merge branch 'yuval-coverage-report' of github.com:sentry-demos/andro…
Jun 21, 2024
976d871
Update codecov-report.yml
yuval-sentry Jun 21, 2024
a28f303
removing unnecessary dependency
Jun 21, 2024
22df8e1
Merge branch 'yuval-coverage-report' of github.com:sentry-demos/andro…
Jun 21, 2024
14a1d54
Update codecov-report.yml
yuval-sentry Jun 21, 2024
36b6dca
Update codecov-report.yml
yuval-sentry Jun 21, 2024
68a5bdc
Update codecov-report.yml
yuval-sentry Jun 21, 2024
dc8e34a
Update codecov-report.yml
yuval-sentry Jun 21, 2024
a2835eb
make sure report is always being generated
Jun 21, 2024
6641709
Merge branch 'yuval-coverage-report' of github.com:sentry-demos/andro…
Jun 21, 2024
7a718b8
update tests
Jun 28, 2024
6afb3e1
add tests
Jun 28, 2024
fa36220
Merge branch 'main' into yuval-coverage-report
sdzhong Jul 2, 2024
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
25 changes: 25 additions & 0 deletions .github/workflows/codecov-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# uploading codecov report

name: Android

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
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
96 changes: 67 additions & 29 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import io.sentry.android.gradle.instrumentation.logcat.LogcatLevel

buildscript {
ext.kotlin_version= '1.8.20'
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
ext.kotlin_version = '1.8.20'
repositories {
mavenCentral()
google()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:7.0.0'
}
}

plugins {
id 'com.android.application'
id "io.sentry.android.gradle" version "4.4.0"
id "jacoco"
}

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'
Expand Down Expand Up @@ -54,6 +51,7 @@ android {
ndk {
abiFilters("x86", "armeabi-v7a", "x86_64", "arm64-v8a")
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
externalNativeBuild {
cmake {
Expand All @@ -65,13 +63,13 @@ android {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig = signingConfigs.debug // to be able to run release mode
buildConfigField("String", "SE", "\"tda\"")
buildConfigField("boolean", "SLOW_PROFILING", "true")
signingConfig signingConfigs.debug // to be able to run release mode
buildConfigField "String", "SE", "\"tda\""
buildConfigField "boolean", "SLOW_PROFILING", "true"
}
debug {
buildConfigField("String", "SE", "\"tda\"")
buildConfigField("boolean", "SLOW_PROFILING", "true")
buildConfigField "String", "SE", "\"tda\""
buildConfigField "boolean", "SLOW_PROFILING", "true"
testCoverageEnabled true
}
}
Expand All @@ -84,10 +82,52 @@ android {
abortOnError false
}
ndkVersion '21.3.6528147'
}

jacoco {
toolVersion = "0.8.5"
}

tasks.withType(Test) {
finalizedBy jacocoTestReport
}

task jacocoTestReport(type: JacocoReport) {
dependsOn 'testDebugUnitTest'

reports {
xml.enabled = true
html.enabled = true
}

def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*'
]

def debugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"

sourceDirectories.setFrom(files([mainSrc]))
classDirectories.setFrom(files([debugTree]))
executionData.setFrom(fileTree(dir: "${buildDir}/jacoco/testDebugUnitTest.exec", includes: ["*.exec"]))
}

tasks.named("jacocoTestReport") {
dependsOn "testDebugUnitTest"
onlyIf = { true }
}

dependencies {
// Room components
def room_version = "2.0.0"

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version" // For Java projects

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation group: 'androidx.constraintlayout', name: 'constraintlayout', version: '1.1.3'
Expand All @@ -96,23 +136,21 @@ 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 'com.google.code.gson:gson:2.10.1'
def fragment_version = "1.5.6"
// Java language implementation
implementation "androidx.fragment:fragment:$fragment_version"

// Warning: upgrading the room version beyond 2.0.0 may
// cause errors running automated Saucelabs tests that generate data.
// If you upgrade the room version, ensure you run associated automated
// tests locally and that they pass.
def room_version = "2.0.0"

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

// Test dependencies
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.11.2'
testImplementation 'org.mockito:mockito-inline:3.11.2'
testImplementation 'org.mockito:mockito-junit-jupiter:3.11.2'

// Android Test dependencies
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}


sentry {
autoUpload = true
uploadNativeSymbols = false
Expand Down
124 changes: 124 additions & 0 deletions app/src/androidTest/java/MainFragmentTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.example.vu.android.empowerplant;

import android.content.Context;
import android.os.Bundle;
import androidx.lifecycle.Lifecycle;
import io.sentry.ITransaction;
import io.sentry.Sentry;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.HashMap;

public class MainFragmentTest {

private MainFragment mainFragment;

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

@Test
public void testMainFragmentNotNull() {
assertNotNull(mainFragment);
}

@Test
public void testOnCreate() {
mainFragment.onCreate(null);
assertNotNull(mainFragment.getArguments());
}

@Test
public void testOnCreateView() {
assertNotNull(mainFragment.onCreateView(null, null, null));
}

@Test
public void testSetBadgeNumber() {
mainFragment.setBadgeNumber();
// Assuming setBadgeNumber increases the badge number by 1
assertEquals(1, mainFragment.mCartItemCount);
}

@Test
public void testFetchToolsFromServer() {
mainFragment.fetchToolsFromServer();
// Assuming fetchToolsFromServer fetches tools, we can check if the progress dialog is shown
assertNotNull(mainFragment.progressDialog);
assertTrue(mainFragment.progressDialog.isShowing());
}

@Test
public void testOnItemClick() {
StoreItem storeItem = new StoreItem();
storeItem.setQuantity(1);
mainFragment.onItemClick(storeItem);
// Assuming onItemClick increases the item count
assertEquals(1, storeItem.getQuantity());
}

@Test
public void testProcessGetToolsResponse() {
mainFragment.processGetToolsResponse("");
// Assuming processGetToolsResponse updates the adapter
assertNotNull(mainFragment.adapter);
}

@Test
public void testProcessProducts() {
mainFragment.processProducts();
// Assuming processProducts calls getIterator, which returns a value
assertEquals(1, mainFragment.getIterator(1));
}

@Test
public void testGetIterator() {
assertEquals(1, mainFragment.getIterator(1));
}

@Test
public void testGetEmpowerPlantDomain() {
assertNotNull(mainFragment.getEmpowerPlantDomain());
}

@Test
public void testCheckout() {
mainFragment.checkout();
// Assuming checkout starts a transaction, check if the transaction is not null
ITransaction transaction = Sentry.startTransaction("checkout [android]", "http.client");
assertNotNull(transaction);
}

@Test
public void testBuildJSONPostData() {
HashMap<String, StoreItem> storeItems = new HashMap<>();
assertNotNull(mainFragment.buildJSONPostData(storeItems));
}

@Test
public void testProcessDeliveryItem() {
ITransaction transaction = Sentry.startTransaction("test", "test");
mainFragment.processDeliveryItem(transaction);
// Assuming processDeliveryItem sets the status
assertEquals(transaction.getStatus(), SpanStatus.OK);
}

@Test
public void testAddAttachment() {
assertTrue(mainFragment.addAttachment());
}

@Test
public void testInsertMultipleStoreItems() {
mainFragment.insertMultipleStoreItems();
// Assuming insertMultipleStoreItems interacts with a database, this is harder to assert directly
}
}
18 changes: 18 additions & 0 deletions app/src/androidTest/java/MockContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.vu.android.empowerplant;

import android.content.Context;
import android.content.ContextWrapper;

public class MockContext extends ContextWrapper {

public MockContext() {
super(null);
}

@Override
public Context getApplicationContext() {
return this;
}

// Add other methods if needed for your specific tests
}
11 changes: 0 additions & 11 deletions app/src/main/java/com/example/vu/android/MainActivityTest.java

This file was deleted.

14 changes: 0 additions & 14 deletions app/src/main/java/com/example/vu/android/MyApplicationTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@
return getIterator(n-1) + getIterator(n-2);
}

public int getNumber() {
int result = getAnotherNumber();
return result;

Check warning on line 286 in app/src/main/java/com/example/vu/android/empowerplant/MainFragment.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/example/vu/android/empowerplant/MainFragment.java#L285-L286

Added lines #L285 - L286 were not covered by tests
}

public int getAnotherNumber() {
return 2;

Check warning on line 290 in app/src/main/java/com/example/vu/android/empowerplant/MainFragment.java

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/example/vu/android/empowerplant/MainFragment.java#L290

Added line #L290 was not covered by tests
}

private String getEmpowerPlantDomain() {
String domain = null;
try {
Expand Down
Loading
Loading