Skip to content

Commit

Permalink
adding coverage plugin and storing reports as artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Feb 17, 2024
1 parent 97fc0f7 commit 2172738
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ jobs:

- name: Build with Gradle Wrapper
run: ./gradlew build

- name: Archive code coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: build/reports
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# [sample-htmx-javalin][00]

[![Java CI with Gradle](https://github.com/sombriks/sample-htmx-javalin/actions/workflows/gradle.yml/badge.svg)](https://github.com/sombriks/sample-htmx-javalin/actions/workflows/gradle.yml)

Sample application showing how htmx teams up with javalin
Expand Down Expand Up @@ -48,12 +49,12 @@ java -jar build/libs/sample-htmx-javalin-1.0-SNAPSHOT-all.jar
- JDBI [fluent api][80] makes database access easier
- TodoItem needs an empty constructor so JDBI bean mapper can fill attributes in
- [Intellij coverage plugin has an issue with velocity][11]
- [JaCoCo plugin][21] just works even the test source set being multilingual

## Next steps

- [ ] Find a good form to object mapper would be handy. Javalin has
[validators][90] but besides that, form to model mapping is pretty much manual
- [ ] Need a coverage solution that handles spock properly
- [ ] Setup docker image building and registry publishing

[00]: https://github.com/sombriks/sample-htmx-javalin
Expand All @@ -68,3 +69,4 @@ java -jar build/libs/sample-htmx-javalin-1.0-SNAPSHOT-all.jar
[90]: https://spockframework.org/spock/docs/2.3/spock_primer.html
[01]: https://javalin.io/tutorials/testing#functionalintegration-tests
[11]: https://youtrack.jetbrains.com/issue/IDEA-274803/Velocity-field-names-check-fails-with-new-coverage#focus=Comments-27-5085668.0-0
[21]: https://docs.gradle.org/current/userguide/jacoco_plugin.html#sec:jacoco_getting_started
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
kotlin("jvm") version "1.9.22"
id("java")
id("groovy")
id("jacoco")
id("application")
id("com.github.johnrengelman.shadow") version "8.1.1"
}
Expand Down Expand Up @@ -42,4 +43,13 @@ tasks.test {
testLogging {
events("passed", "skipped", "failed")
}
finalizedBy(tasks.jacocoTestReport)
}

//https://docs.gradle.org/current/userguide/jacoco_plugin.html#sec:jacoco_report_configuration
tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
csv.required = true
}
}
1 change: 0 additions & 1 deletion src/main/kotlin/sample/htmx/controller/TodoController.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sample.htmx.controller

import io.javalin.http.Context
import io.javalin.http.bodyAsClass
import org.slf4j.LoggerFactory
import sample.htmx.model.TodoItem
import sample.htmx.service.TodoService
Expand Down
9 changes: 0 additions & 9 deletions src/test/groovy/sample/htmx/AppTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ import spock.lang.Specification

class AppTest extends Specification {

def app = new App()
def dotenv = Dotenv.configure().load()

def "Should check app got dependencies properly injected"() {
expect:
app.javalin != null
app.controller != null
app.controller.service != null
app.controller.service.db != null
}

def "should check env is test"() {
when:
def mode = dotenv.get("MODE")
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/sample/htmx/ApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ApiTest {
}

@Test
fun `Should check endpoints`() = JavalinTest.test(app.javalin) { server, client ->
fun `Should check TodoItem endpoints`() = JavalinTest.test(app.javalin) { server, client ->
// basic GET endpoints
Assertions.assertEquals(200, client.get("/").code)
Assertions.assertEquals(200, client.get("/todos").code)
Expand Down

0 comments on commit 2172738

Please sign in to comment.