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

Added App Unit Testing Logs & Removed Redundant Line in Gradle WorkFlow #121

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Build with Gradle Wrapper
- name: Build & Test with Gradle Wrapper
run: ./gradlew build
working-directory: DAIRemoteApp

- name: Run tests with Gradle Wrapper
run: ./gradlew test
working-directory: DAIRemoteApp

53 changes: 53 additions & 0 deletions DAIRemoteApp/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
alias(libs.plugins.android.application)
id("de.mannodermaus.android-junit5") version "1.11.2.0"
Expand Down Expand Up @@ -44,4 +46,55 @@ dependencies {
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
testImplementation("org.mockito:mockito-core:5.14.2")
}

// Test Logging
tasks.withType<Test> {
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events("started", "skipped", "passed", "failed")
showStandardStreams = true
}

var totalTests = 0
var passedTests = 0
var failedTests = 0
var skippedTests = 0

// Track test statuses
addTestListener(object : TestListener {
override fun beforeTest(testDescriptor: TestDescriptor) {
// Do nothing
}

override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
totalTests++
when (result.resultType) {
TestResult.ResultType.SUCCESS -> passedTests++
TestResult.ResultType.FAILURE -> failedTests++
TestResult.ResultType.SKIPPED -> skippedTests++
}
}

override fun beforeSuite(suite: TestDescriptor) {
// Do nothing
}

override fun afterSuite(suite: TestDescriptor, result: TestResult) {
if (suite.parent == null) {
println(
"""
-------------
Test Summary:
-------------
Total: $totalTests
Passed: $passedTests
Failed: $failedTests
Skipped: $skippedTests
-------------
""".trimIndent()
)
}
}
})
}
Loading